As a part of my API, I have an abstract BaseEntity class. I would like to provide a way to somehow hook into new properties that are introduced in the descendants of this class. What I was thinking is this:
public class MyEntity : BaseEntity
{
[DataElement]
public int NewProperty { get; set; }
}
If I could write an attribute DataElement
that would hook in the getter and setter, then my API would be made aware of this property on access.
Is this possible?
UPD: I'll try to explain where this comes from. I have this BaseEntity that does not have any data by itself. Its descendants will declare what data they may hold as properties. I want to be able to iterate through all the data the object has (to store it in the database in a very specific form). One way to do it is reflection. But I thought about doing it via attributes that would register the data whenever the property is accessed.