Basically I have a class like this:
public class A
{
public A()
{
}
public Guid Key { get; set; }
public long PrimaryId { get; set; }
public bool IsActive { get; set; }
public Dictionary<string, string> Dict { get; set; }
public Dictionary<int, string> Dict1 { get; set; }
}
Based on the answer here, I can use TypeDescriptor which works great for non-nested collections. For nested collections and dictionary I use a method like this:
private static bool IsEnumerable(PropertyInfo pi)
{
// note: we could also use IEnumerable (but string, arrays are IEnumerable...)
return typeof(ICollection).IsAssignableFrom(pi.PropertyType);
}
private static bool IsDictionary(PropertyInfo pi)
{
return pi.PropertyType.IsGenericType && pi.PropertyType.GetGenericTypeDefinition() == typeof(Dictionary<,>);
}
However, if someone can help with a method which converts a generic list to DataTable. That will be great.