Type type = typeof (Model.users). GetProperties () [i]. PropertyType; Determines whether the type is generic, because nullable is a generic class, if (type. Isgenerictype && type. GetGenericTypeDefinition (). Equals (typeof (Nullable<>))//Determines if Convertsiontype is a Nullable generic class { //if Type is a Nullable class, Declares a Nullableconverter class that provides conversions from the nullable class to the underlying primitive type System.ComponentModel.NullableConverter nullableconverter = New System.ComponentModel.NullableConverter (type); Converts the type to the base primitive type of the nullable pair type = Nullableconverter.underlyingtype; } typeof (Model.users). GetProperty (typeof (Model.users). GetProperties () [i]. Name). SetValue (U,convert.changetype (dic[item],type), null);
Before making some complex type conversions (such as converting a data to a property type, the property may be a nullable type) first determine whether the type is a nullable type, otherwise it will report the following error: