samedi 1 août 2015

Alternatives for BaseType, IsDefined and GetField in a portable class library

I want to convert my class library to a portable one but my code contains a lot of reflection methods that do not exist in portable class library (PCL) targets I tired so far. Please help me to find the appropriate one and if there is no target that supports BaseType, IsDefined and GetField please let me know if there are any alternatives:

var fieldInfos = GetType().GetRuntimeFields();
foreach (var item in fieldInfos)
{
    Type t = item.FieldType;
    ...
    if (t.BaseType == typeof(...))
    {
        if (!Attribute.IsDefined(GetType().GetField(item.Name),typeof(Optional)))
    }
}

In this code compilers cannot find the BaseType, IsDefined and GetField properties, after I converted class library to a PCL. And please let me know if you think this is not a good idea to put reflection code in a portable library.





Aucun commentaire:

Enregistrer un commentaire