Converting dynamic type to dictionary C#

You can fill the dictionary using reflection:

public Dictionary<String, Object> Dyn2Dict(dynamic dynObj)
{
     var dictionary = new Dictionary<string, object>();
     foreach (PropertyDescriptor propertyDescriptor in TypeDescriptor.GetProperties(dynObj))
     {
        object obj = propertyDescriptor.GetValue(dynObj);
        dictionary.Add(propertyDescriptor.Name, obj);
     }
     return dictionary;
}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)