Reputation: 187
In code listed bellow I need determine type of TSource. Parsed parameter can be, for example IList, or only Car etc. In method Model.Map<> I need parse type of generic type. Everything works fine when parsed parameter is single object (Car, Boat...). Problem is when collection is parsed. So, I need to cover case when parameter is collection.
public class Convert<TSource, TDestination>
{
public static TDestination ToModel(TSource source)
{
Model.Map<TSource, TDestination>();
}
}
Upvotes: 0
Views: 1223
Reputation: 28970
You can try with - based on GetGenericArguments
var type = source.GetType().GetGenericArguments()[0];
Link : http://msdn.microsoft.com/fr-fr/library/system.type.getgenericarguments.aspx
Upvotes: 4