Working with .NET 2 in mono, I\'m using a basic JSON library that returns nested string, object Dictionary and lists.
I\'m writing a mapper to map this
Modifying the above answer. In order to use GetGenericTypeDefinition() you must preface the method with GetType(). If you look at MSDN this is how GetGenericTypeDefinition() is accessed:
public virtual Type GetGenericTypeDefinition()
Here is the link: https://msdn.microsoft.com/en-us/library/system.type.getgenerictypedefinition(v=vs.110).aspx
public bool IsList(object o)
{
return o is IList &&
o.GetType().IsGenericType &&
o.GetType().GetGenericTypeDefinition().IsAssignableFrom(typeof(List<>));
}
public bool IsDictionary(object o)
{
return o is IDictionary &&
o.GetType().IsGenericType &&
o.GetType().GetGenericTypeDefinition().IsAssignableFrom(typeof(Dictionary<>));
}