Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
このメソッドを実装する最良の方法は次のとおりです。
Type GetNullableTypeFromType(Type tp);
となることによって
Type tpString = GetNullableTypeFromType(typeof(string)); // Returns typeof(string) Type tpInt = GetNullableTypeFromType(typeof(int)); // Returns typeof(int?)
public static Type GetNullableType(Type t) { if (t.IsValueType && (Nullable.GetUnderlyingType(t) == null)) return typeof(Nullable<>).MakeGenericType(t); else return t; }