jeudi 23 juillet 2015

Create a property and its type dynamically using propertydescriptor

I have a class that will has 2 properties

public class PropertyBag
{
    public string PropertyName {get;set;}
    public object PropertyValue {get;set;}
}

so this "PropertyValue" property can hold any primitive datatype i.e. int, datetime, string, etc.

I am reading settings from custom configuration file with nested elements. Something like this:

<Workspace name="ws1">
  <property name="version" type="decimal"> 1.3 </property>
  <property name="datetime" type="datetime"> 10-10-2015 </property>
  <property name="mainwindowlocation" type="string"> 10 300 850 </property>
  ...more nested elements...
</Workspace>  

I want to be able to set the type of the "PropertyValue" property dynamically based on the value from the config file. A colleague mentioned about PropertyDescriptors/TypeDescriptors/dynamic. Any suggestions with specific implementation detail ?

Thanks





Aucun commentaire:

Enregistrer un commentaire