There is no difference what type of the property you use.
Your mistake is
Convert
. (This class haunts CodeProject inquirers. How infected everyone with this abusing this type?) You probably fail to understand that all types inherit from
System.Object
, which is a parameter type of
System.Reflection.PropertyInfo.SetValue
. Even primitive and enumeration types are used as object (through
boxing
; you need to understand very well how boxing works) in this method.
You need to use value directly:
PropertyInfo piMargin =
PropertyInfo piFont =
PropertyInfo piWidth =
int newWidth =
piMargin.SetValue(myObject, new Margin( ), null);
piFont.SetValue(myObject, new Font(( ), null);
piWidth.SetValue(myObject, newWidth, null);
—SA