Is it possible to create property in a class via code at runtime (Like ViewBag of MVC3) in C#?
I want to create property of custom type in a class as we create property in ViewBag of MVC3.
Thanks.
Is it possible to create property in a class via code at runtime (Like ViewBag of MVC3) in C#?
I want to create property of custom type in a class as we create property in ViewBag of MVC3.
Thanks.
Use a Dictionary - this will allow you to add as many "properties" as you wish.
The dynamic type in .NET 4 will allow you to create properties at runtime; I think ViewBag is actually an instance of the dynamic type.
By the way, I think what you're looking for is creating properties at runtime - creating properties at compile time would mean adding a getter and a setter to your code as you would normally do!