vendredi 18 août 2017

Elegant Reflection Framework in .NET

Is there any open-source C# project available as a replacement for reflection providing an abstraction layer for ease of use and is also effective and useful in terms of performance and working.

I was searching on the web and found many such frameworks, e.g.

But no time to evaluate, so seeking some quick expert opinion on this. My goal is to replace many of the extension methods that I have defined to ease the reflection usage as shown below:

    public static Array CreateArrayInstance(this PropertyInfo propInfo, int length)
    {
        if (propInfo.PropertyType.IsArray)
        {
            var arrayType = propInfo.PropertyType.GetElementType();
            return Array.CreateInstance(arrayType, length);
        }
        return null;
    }

    public static IList CreateGenericListInstance(this PropertyInfo propInfo)
    {
        var type = propInfo.PropertyType.GenericTypeArguments[0];
        var listType = typeof(List<>).MakeGenericType(type);
        var listInstance = (IList)Activator.CreateInstance(listType);
        return listInstance;
    }

OR suggest some good and smart approach to handle instead of creating so many scattered extension methods.





Aucun commentaire:

Enregistrer un commentaire