static internal void SafeChildAdd( SecurityElement parent, ISecurityElementFactory child, bool copy )
{
if (child == parent)
return;
if (child.GetTag().Equals( "IPermission" ) || child.GetTag().Equals( "Permission" ))
{
parent.AddChild( child );
}
else if (parent.Tag.Equals( child.GetTag() ))
{
Contract.Assert( child is SecurityElement, "SecurityElement expected" );
SecurityElement elChild = (SecurityElement)child;
Contract.Assert( elChild.InternalChildren != null,
"Non-permission elements should have children" );
for (int i = 0; i < elChild.InternalChildren.Count; ++i)
{
ISecurityElementFactory current = (ISecurityElementFactory)elChild.InternalChildren[i];
Contract.Assert( !current.GetTag().Equals( parent.Tag ),
"Illegal to insert a like-typed element" );
parent.AddChildNoDuplicates( current );
}
}
else
{
parent.AddChild( (ISecurityElementFactory)(copy ? child.Copy() : child) );
}
}