I want to add the properties to the class / object dynamically in c# in VS 3.5. how can i do this?
Asked
Active
Viewed 3,011 times
0
-
3http://stackoverflow.com/questions/947241/c-dynamic-properties – x2. Aug 20 '10 at 06:24
2 Answers
1
If you want to create an object that supports run-time addition of properties, and you can use C# 4.0, you can use System.Dynamic.ExpandoObject
dynamic myObject = new ExpandoObject();
myObject.AnswerToUltimateQuestionOfTheUniverse = 42;
EDIT: I see that you have now explictly mentioned C# 3.0. This is no longer applicable.

Ani
- 111,048
- 26
- 262
- 307
-
-
please see again , I have mentioned 3.5 not 3.0. I think we can do this by Dictionary or Hash table but how to achieve exact? – Red Swan Aug 20 '10 at 09:13
0
Attach additional responsibilities to an object dynamically with the Decorator Pattern: http://www.dofactory.com/Patterns/PatternDecorator.aspx

ChatGPT
- 5,334
- 12
- 50
- 69