public static Type CloseNullableType(this CodeTypeReference reference) { if (!reference.IsNullableType()) { throw new InvalidOperationException("The current code type reference is not a nullable type."); } Type valueType = Type.GetType(reference.TypeArguments[0].BaseType); return typeof(Nullable<>).MakeGenericType(valueType); }