views:

40

answers:

1

I'm curious how to check if given type is closed version of open type. For instance

public bool IsGenericList(Type source)
{
    return (source.IsGenericType &&
            /*here goes the manipulation on source type*/ == typeof(List<>));
}
+5  A: 

Try Type.GetGenericTypeDefinition:

public bool IsGenericList(Type source)
{
    return source.IsGenericType &&
           source.GetGenericTypeDefinition() == typeof(List<>);
}
Jon Skeet
This is what I had tried at the first place but thought it doesn't work because I had bug somewhere else in code. Thanks anyway :)
jethro