Freigeben über


How to identify a Nullable

Before the recent Nullable<T> changes, some of you may have used INullableValue to find a Nullable<T>. We could debate the issues with writing code that uses a "marker" interface but here I want to just provide a solution for deciding if a type is Nullable<T>.

Now that the INullableValue interface is gone from Nullable<T>, I have got questions about how to identify a Nullable<T> type. Here is a way to do it:

if

(type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>)) {…}