I got a list of different objects that I defined in different classes and I’d like to add a string property “Name” to all these objects. Is that possible ?
I don’t have that much code to provide as my classes are very simple/classic ones.
Thanks in advance for any help !
(edit : I don’t want to inherit from an abstract class that adds this property ! In fact, I don’t want to modify at all my class that define my object. That’s what i call “Dynamically” in the title.
What I want is something like :
myObject.AddProperty(string, "Name");
or
myObject.AddAttribute(string, "Name");
(I don’t know how it is exactly called)
and then I can do :
myObject.Name = "blaaa";
Create an abstract class that all of your other classes could inherit:
EDIT (per new requirement)
Since you don’t want to touch the original classes in the DLL, I’d take this [similar] approach:
Notice that
Foois now a partial class. You’re not touching the existing class definition in the DLL, you’re extending it.EDIT (per newer new requirement)
Given your requirements (no editing of original class), what you’re asking is not possible.