EDN Admin
Well-known member
<p align=left>Hello,
<p class=MsoNormal style="margin:0cm 0cm 0pt <font size=3><font face=Calibri><span style=" I need an implementation of an object with dynamic properties in C#, full .NET 3.x, such that I can add any number of properties to the object at runtime.</font></font>
<p class=MsoNormal style="margin:0cm 0cm 0pt <font size=3><font face=Calibri><span style=" Can you give me some advice, please?</font></font>
<p class=MsoNormal style="margin:0cm 0cm 0pt <font face=Calibri size=3> </font>
<p class=MsoNormal style="margin:0cm 0cm 0pt <font size=3><font face=Calibri><span style=" Eg. Lets say I have Product object with dynamic properties. 1. Product instance can have Name and Price property, 2. instance Name, Price, ElectricConductivity, 3. instance Name, Price, ThermalConductivity ...</font></font>
<p class=MsoNormal style="margin:0cm 0cm 0pt <font size=3><font face=Calibri><span style=" I need something like dependency properties in WPF, but without UI overhead so that such objects can be stored easily to an object database like db4o.</font></font>
<p class=MsoNormal style="margin:0cm 0cm 0pt <font size=3><font face=Calibri><span style=" Name and Price properties could be normal .NET properties with backing class field, but ElectricConductivity and ThermalConductivity and others are optional so they should not be precompiled.</font></font>
<p class=MsoNormal style="margin:0cm 0cm 0pt <font size=3><font face=Calibri><span style=" One approach can be to use Dictionary<PropertyKey, object> with property key to its value map or a IList<DynamicProperty> where DynamicProperty has PropertyKey and its value. PropertyKey should have property name, type, validation and change callbacks, some metadata with UI editors etc. Than ICustomTypeDescriptor can be implemented as well.</font></font>
<p class=MsoNormal style="margin:0cm 0cm 0pt <font size=3><font face=Calibri><span style=" Another way I am thinking of is to use IDynamicType implementation from DLR. Will be DLR available in full .NET or only in Silverlight.NET? I have read that no default IDynamicType implementation will be included in DLR, but IronRuby or IronPython have its own one. So will there be IDynamicType implementation in full .NET I can directly use from C#?</font></font>
<p class=MsoNormal style="margin:0cm 0cm 0pt <font face=Calibri size=3> </font>
<p class=MsoNormal style="margin:0cm 0cm 0pt <font size=3><font face=Calibri><span style=" What you think is the best way to implement such object with dynamic properties?</font></font>
<p class=MsoNormal style="margin:0cm 0cm 0pt <font face=Calibri size=3> </font>
<p class=MsoNormal style="margin:0cm 0cm 0pt <font face=Calibri size=3>Thanks</font>
<p class=MsoNormal style="margin:0cm 0cm 0pt <font size=3><font face=Calibri><span style=" Marek Istvanek</font></font>
<p class=MsoNormal style="margin:0cm 0cm 0pt <font size=3><font face=Calibri></font></font>
<p align=left>
View the full article
<p class=MsoNormal style="margin:0cm 0cm 0pt <font size=3><font face=Calibri><span style=" I need an implementation of an object with dynamic properties in C#, full .NET 3.x, such that I can add any number of properties to the object at runtime.</font></font>
<p class=MsoNormal style="margin:0cm 0cm 0pt <font size=3><font face=Calibri><span style=" Can you give me some advice, please?</font></font>
<p class=MsoNormal style="margin:0cm 0cm 0pt <font face=Calibri size=3> </font>
<p class=MsoNormal style="margin:0cm 0cm 0pt <font size=3><font face=Calibri><span style=" Eg. Lets say I have Product object with dynamic properties. 1. Product instance can have Name and Price property, 2. instance Name, Price, ElectricConductivity, 3. instance Name, Price, ThermalConductivity ...</font></font>
<p class=MsoNormal style="margin:0cm 0cm 0pt <font size=3><font face=Calibri><span style=" I need something like dependency properties in WPF, but without UI overhead so that such objects can be stored easily to an object database like db4o.</font></font>
<p class=MsoNormal style="margin:0cm 0cm 0pt <font size=3><font face=Calibri><span style=" Name and Price properties could be normal .NET properties with backing class field, but ElectricConductivity and ThermalConductivity and others are optional so they should not be precompiled.</font></font>
<p class=MsoNormal style="margin:0cm 0cm 0pt <font size=3><font face=Calibri><span style=" One approach can be to use Dictionary<PropertyKey, object> with property key to its value map or a IList<DynamicProperty> where DynamicProperty has PropertyKey and its value. PropertyKey should have property name, type, validation and change callbacks, some metadata with UI editors etc. Than ICustomTypeDescriptor can be implemented as well.</font></font>
<p class=MsoNormal style="margin:0cm 0cm 0pt <font size=3><font face=Calibri><span style=" Another way I am thinking of is to use IDynamicType implementation from DLR. Will be DLR available in full .NET or only in Silverlight.NET? I have read that no default IDynamicType implementation will be included in DLR, but IronRuby or IronPython have its own one. So will there be IDynamicType implementation in full .NET I can directly use from C#?</font></font>
<p class=MsoNormal style="margin:0cm 0cm 0pt <font face=Calibri size=3> </font>
<p class=MsoNormal style="margin:0cm 0cm 0pt <font size=3><font face=Calibri><span style=" What you think is the best way to implement such object with dynamic properties?</font></font>
<p class=MsoNormal style="margin:0cm 0cm 0pt <font face=Calibri size=3> </font>
<p class=MsoNormal style="margin:0cm 0cm 0pt <font face=Calibri size=3>Thanks</font>
<p class=MsoNormal style="margin:0cm 0cm 0pt <font size=3><font face=Calibri><span style=" Marek Istvanek</font></font>
<p class=MsoNormal style="margin:0cm 0cm 0pt <font size=3><font face=Calibri></font></font>
<p align=left>
View the full article