how to test if a given ctype is of a given template?

L

Lloyd Dupont

I would like to know if a type 'aType' is a Nullable<T>

With the debugger I have tried
typeof(Nullable<>).IsSubclassOf(typeof(Nullable<int>)
typeof(Nullable<int>).IsSubclassOf(typeof(Nullable<>)
typeof(Nullable<>).IsAssignableFrom(typeof(Nullable<int>)
typeof(Nullable<int>).IsAssignableFrom(typeof(Nullable<>)

They all 4 return false :S
Any tip?
 
L

Lloyd Dupont

found it:
if (ft.IsGenericType && ft.GetGenericTypeDefinition() == typeof(Nullable<>))
.......
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top