B
Ben Galvin
Hi,
I'm looking for an equivalent to the C++ 'friend' keyword in C# (for those
who don't know, this lets you give a specific class access to all the
private/protected members of another class).
I'm trying to write an object persistence mechanism where all of the
persistence logic for each class is situated in a seperate class (the Mapper
design pattern). The object itself is completely unaware of how it is being
persisted. This lets someone in the future write a new persistence layer
(e.g. to a different DBMS) without modifying the object code. The difficulty
is that this persistence class needs priviledged access to the class it is
trying to persist (i.e. it needs to set/get private members which ordinarily
shouldn't be accessed by code outside the class). In C++ you can do this
with the 'friend' keyword.
I'm aware you can do this with the 'internal' keyword, however this seems
much too coarse. I don't want to allow every piece of code in the assembly
to mess around with the internals of every other class. I don't want to use
a 3rd party object persistence framework as it needs to be very fast, and I
need a lot of control over it.
Is there any other way of doing this cleanly, or plans to allow this in C#
2.0?
Thanks,
Ben
I'm looking for an equivalent to the C++ 'friend' keyword in C# (for those
who don't know, this lets you give a specific class access to all the
private/protected members of another class).
I'm trying to write an object persistence mechanism where all of the
persistence logic for each class is situated in a seperate class (the Mapper
design pattern). The object itself is completely unaware of how it is being
persisted. This lets someone in the future write a new persistence layer
(e.g. to a different DBMS) without modifying the object code. The difficulty
is that this persistence class needs priviledged access to the class it is
trying to persist (i.e. it needs to set/get private members which ordinarily
shouldn't be accessed by code outside the class). In C++ you can do this
with the 'friend' keyword.
I'm aware you can do this with the 'internal' keyword, however this seems
much too coarse. I don't want to allow every piece of code in the assembly
to mess around with the internals of every other class. I don't want to use
a 3rd party object persistence framework as it needs to be very fast, and I
need a lot of control over it.
Is there any other way of doing this cleanly, or plans to allow this in C#
2.0?
Thanks,
Ben