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
Use the is
keyword and reflection.
public bool IsList(object o)
{
if(o == null) return false;
return o is IList &&
o.GetType().IsGenericType &&
o.GetType().GetGenericTypeDefinition().IsAssignableFrom(typeof(List<>));
}
public bool IsDictionary(object o)
{
if(o == null) return false;
return o is IDictionary &&
o.GetType().IsGenericType &&
o.GetType().GetGenericTypeDefinition().IsAssignableFrom(typeof(Dictionary<,>));
}