February 13th, 2012, 04:31 PM
Dynamic Property Name in Class/Interface?
Is there any way that I can "define" the PropertyName in a class at runtime/compiling? Either by through the constructor add the PropertyName or something else.
Say I have a class that should contain two Properties but I don't want to name them. Much like <T>, I want it to be used with different types - all I know is there should be two Fields.
And to get the the data from that property without knowing it's name, is by searching the object/class for all its properties. I have an interface, an abstract class that inherits its, and other classes that inherits it. BUT, the BaseClass has a method that shows all the PropertyValues of the class as long as it's not part of the BaseClass.
So, what I'm trying to say is:
Interface -> Base Class (With method for getting PropertyName & PropertyValue of object that is not part of Base Class) -> Child Class
so if I:
Base Class.GetAllProperties(); // returns null
but if I have a Property named "Name" in Child Class:
Child Class.GetAllProperties(); // returns "Name : My Name"
so, this way when I build a system that has Properties that isn't know at the time, it works. Therefor I would like to know if there's any way to implement this?
Create a property at runtime or anything like that.
Tags for this Thread
Click Here to Expand Forum to Full Width
This is a CodeGuru survey question.