how to set nullable type via reflection code ( c#)?

后端 未结 8 1337
我寻月下人不归
我寻月下人不归 2020-12-28 16:05

I need to set the properties of a class using reflection.

I have a Dictionary with property names and string values.

Inside

8条回答
  •  [愿得一人]
    2020-12-28 16:31

    Checking for Nullable types is easy, int? is actually System.Nullable. So you just check if the type is a generic instance of System.Nullable. Setting shouldn't make a difference, nullableProperty.SetValue(instance, null) or nullableProperty.SetValue(instance, 3)

提交回复
热议问题