Nullable<> プロパティを動的に設定しようとしています。
私は自分の財産を取得します例:
PropertyInfo property = class.GetProperty("PropertyName"); // My property is Nullable<> at this time So the type could be a string or int
次のようなリフレクションでプロパティを設定したい
property.SetValue(class,"1256",null);
プロパティが Nullable<> ジェネリックの場合、機能しません。だから私は私の財産を設定する方法を見つけようとします。
私の nullable<> プロパティのタイプを知るために、私は実行します
Nullable.GetUnderlyingType(property.PropertyType)
何か案が ?
Nullable<> プロパティのインスタンスを作成しようとしています
var nullVar = Activator.CreateInstance(typeof(Nullable<>).MakeGenericType(new Type[] { Nullable.GetUnderlyingType(property.PropertyType) }));
ただし、nullVar は常に Null です