dimanche 20 décembre 2015

How can I convert the following code to a Compiled Expression in C#?

I have a piece of code which is responsible for creating a generic list using reflection.

public static IList MakeList(Type listType)
{
    // checks to ensure listType is a generic list omitted...

    // gets the generic argument e.g. string for a List<string>
    var genericType = listType.GetGenericArguments()[0];

    return (IList)typeof(List<>)
        .MakeGenericType(genericType)
        .GetConstructor(Type.EmptyTypes)
        .Invoke(null);
}

How can I convert this to a compiled expression to benefit from the performance benefits?





Aucun commentaire:

Enregistrer un commentaire