Re: Not able to add child CodeGroups
From: Greg Fee (gregfee_at_microsoft.com)
Date: 06/10/03
- Previous message: Greg Fee: "RE: MemberwiseClone exploitable?"
- In reply to: Keith: "Re: Not able to add child CodeGroups"
- Next in thread: Keith: "Re: Not able to add child CodeGroups"
- Reply: Keith: "Re: Not able to add child CodeGroups"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Date: Mon, 09 Jun 2003 22:25:49 GMT
Hi,
Looks like you need to follow the recursive 'set' pattern to get your
changes into the live objects. I think your _metaCodeGroup will be a child
of the RootCodeGroup. Therefore after you make the change you need to
visit the RootCodeGroup's children and replace the existing equivalent
instance of _metaCodeGroup with the current one. I accomplish this in the
caspol code by remembering where in the list of children the code group I'm
going to manipulate is. Vaguely something like (pseudo-code, no guarantees
here):
void FindCodeGroup( CodeGroup parent, String name, out CodeGroup target,
out int position )
{
position = 1;
target = null;
IEnumerator enumParentChildren = parent.Children.GetEnumerator();
while (enumParentChildren.MoveNext())
{
if (((CodeGroup)enumParentChildren).Name).Equals( name ))
{
target = (CodeGroup)enumParentChildren;
break;
}
position++;
}
}
void SetCodeGroup( CodeGroup parent, CodeGroup target, int position )
{
int currentPosition = 1;
target = null;
IEnumerator enumParentChildren = parent.Children.GetEnumerator();
ArrayList newChildren = new ArrayList();
while (enumParentChildren.MoveNext())
{
if (position == currentPosition)
{
newChildren.Add( target );
}
else
{
newChildren.Add( enumParentChildren.Current );
}
currentPosition++;
}
parent.Children = newChildren;
}
If you are dealing with an arbitrary level in the tree, you potentially
need to maintain a stack of this data so that you can record the results of
FindCodeGroup and then use that in SetCodeGroup once you've manipulated the
code group of your choosing.
Greg
- Previous message: Greg Fee: "RE: MemberwiseClone exploitable?"
- In reply to: Keith: "Re: Not able to add child CodeGroups"
- Next in thread: Keith: "Re: Not able to add child CodeGroups"
- Reply: Keith: "Re: Not able to add child CodeGroups"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]