D
Danny Tuppeny
Hi all,
The next few paragraphs put my question in context, but feel free to
skip down to the end if you don't care *why* I need the answer!
****************************************
*** Start of long-winded description ***
****************************************
I've got some classes that define a tree structure. When the Parent
property of an item is changed, it automatically updates the Children list.
The opposite is also true - if you add an item to a Children list, it's
parent is automatically updated.
The way this second part works, is with an event (fired when items are
added to the list) like this:
children.Added += delegate(object sender,
ChildList<T>.ChildListEventArgs<T> e) { e.Item.parent = (T)this; };
Notice the lowercase p in parent. If I change this to a P, then I'll get
a StackOverflow, because setting the parent, adds to the child list, and
adding to the child list sets the parent. This works fine, because
everything is in one class (the tree is a tree of one type).
Now, I've extended it slightly to support ClassA having children of
ClassB, and ClassB has a parent of ClassA.
My problem, is that from within ClassB, when the child list is modified,
I need to set the parent of ClassA. My current method requires that the
parentClassB property within ClassA be internal (if I use the public
property, I'll overflow the stack again). However, it's important people
(me) don't "accidentally" use this variable when meaning to use the
public property (else my magic code won't get called, undermining the
whole point of me abstracting the tree stuff!).
****************************************
*** End of long-winded description ***
****************************************
So... In short - is there any way to restrict access, like "internal",
but only to subset of classes within the DLL?
If not, the only way to make sure my code is used properly, is to move
ClassA and ClassB into a separate DLL, so only they can set each others
internal data.
The problem with that, is that ClassA and ClassB then need to be public,
and that means anyone can reference my DLL and use my classes, whereas
if everything is in one, they can be internal classes.
Are there any solutions? :-(
The next few paragraphs put my question in context, but feel free to
skip down to the end if you don't care *why* I need the answer!
****************************************
*** Start of long-winded description ***
****************************************
I've got some classes that define a tree structure. When the Parent
property of an item is changed, it automatically updates the Children list.
The opposite is also true - if you add an item to a Children list, it's
parent is automatically updated.
The way this second part works, is with an event (fired when items are
added to the list) like this:
children.Added += delegate(object sender,
ChildList<T>.ChildListEventArgs<T> e) { e.Item.parent = (T)this; };
Notice the lowercase p in parent. If I change this to a P, then I'll get
a StackOverflow, because setting the parent, adds to the child list, and
adding to the child list sets the parent. This works fine, because
everything is in one class (the tree is a tree of one type).
Now, I've extended it slightly to support ClassA having children of
ClassB, and ClassB has a parent of ClassA.
My problem, is that from within ClassB, when the child list is modified,
I need to set the parent of ClassA. My current method requires that the
parentClassB property within ClassA be internal (if I use the public
property, I'll overflow the stack again). However, it's important people
(me) don't "accidentally" use this variable when meaning to use the
public property (else my magic code won't get called, undermining the
whole point of me abstracting the tree stuff!).
****************************************
*** End of long-winded description ***
****************************************
So... In short - is there any way to restrict access, like "internal",
but only to subset of classes within the DLL?
If not, the only way to make sure my code is used properly, is to move
ClassA and ClassB into a separate DLL, so only they can set each others
internal data.
The problem with that, is that ClassA and ClassB then need to be public,
and that means anyone can reference my DLL and use my classes, whereas
if everything is in one, they can be internal classes.
Are there any solutions? :-(