mardi 29 décembre 2015

Get the type and value of Sub Class where you only have Sub Class name as a string

I'm trying to assemble a generic method which is passed an object of a class type (ie: dbJob) and also the name of a sub class like 'LastUpdatedDate' and a process string, which can be '> 01-01-2015'.

The method looks like this

public bool checkProcess(object obj, string className, string processStr)
{
    PropertyInfo[] propertyInfo;
    bool returnValue = false;
    propertyInfo = obj.GetType().GetProperties();
    for (int i = 0; i < propertyInfo.Length; i++)
    {
        if (propertyInfo[i].Name == propName)
        {
            var objType = propertyInfo[i].GetType();
            var objValue = propertyInfo[i].GetValue(this, null);
            returnValue = qualifyClass(objType, objValue);
            if (!returnValue)
            {
                break;
            }
        }
    }
    //propertyInfo className evaluate processStr
    return returnValue; 
} 

When the method runs, objectType just holds {System.Type{System.RuntimeType}} and objValue crashes saying 'Object is not of the same type'. I just need the type and value of the Sub Class that matches propName, where am I going wrong?





Aucun commentaire:

Enregistrer un commentaire