I need to add some information to a class of type DataRecord
I would like to embed in every instance inheriting from IDataRecord a Dictionary
Is it possible to achieve this using Extension Fields? (something like Extension Method)
I need to add some information to a class of type DataRecord
I would like to embed in every instance inheriting from IDataRecord a Dictionary
Is it possible to achieve this using Extension Fields? (something like Extension Method)
No, there is no such feature in C#.
It wouldn't really make sense to add it either, as there wouldn't be a well defined location to store the data for that field. Dynamically increasing the size of an existing object isn't really feasible, given the design of the language. It's important that the size of all object instances is constant.
No, this is not possible. Extension methods are nothing more than static methods which are passed the object as this
reference.
Alternatives:
ClassWithDictionary<MyClassA>
which kind of decorates the original object