I need to set the properties of a class using reflection.
I have a Dictionary<string,string> with property names and string values.
Inside a reflection loop, I need to convert the string value to the appropriate property type while setting the value for each property. Some of these property types are nullable types.
- How can I know from PropertyInfo if the property is a nullable type?
- How can I set a nullable type using reflection?
edit: The first method defined in the comments on this blog seems to do the trick as well: http://weblogs.asp.net/pjohnson/archive/2006/02/07/437631.aspx
One way to do this is:
Just set is as per any other reflection code: