Exemplo n.º 1
0
    public static object GetValueByJsonPropertyName(this object instance, string propertyName)
    {
        string[]            ts     = propertyName.Split('.');
        JsonMemberAttribute result = null;
        object tempValue           = instance;

        for (int i = 0; i < ts.Length; i++)
        {
            string tpn = ts[i];
            result    = tempValue.GetType().GetJsonMember(tpn);
            tempValue = result.GetValue(tempValue, false);
        }
        return(tempValue);
    }
Exemplo n.º 2
0
    public static void SetValueByJsonPropertyName(this object instance, string propertyName, object value)
    {
        string[]            ts          = propertyName.Split('.');
        JsonMemberAttribute resultPinfo = null;
        object tempValue    = instance;
        object parentObject = null;

        for (int i = 0; i < ts.Length; i++)
        {
            string tpn = ts[i];
            resultPinfo  = tempValue.GetType().GetJsonMember(tpn);
            parentObject = tempValue;
            tempValue    = resultPinfo.GetValue(tempValue, false);
        }
        resultPinfo.SetValue(parentObject, value);
    }