public static TokenBasedSet CopyTokenBasedSet( TokenBasedSet set )
{
if (set == null || set.GetCount() == 0)
return null;
int maxIndex = set.GetMaxUsedIndex();
TokenBasedSet copySet = new TokenBasedSet( maxIndex + 1, 4 );
for (int i = 0; i <= maxIndex; ++i)
{
Object obj = set.GetItem( i );
if (obj == null)
copySet.SetItem( i, null );
else if (obj is IPermission)
copySet.SetItem( i, ((IPermission)obj).Copy() );
else if (obj is PermissionList)
copySet.SetItem( i, ((PermissionList)obj).Copy() );
else
{
BCLDebug.Assert( false, "CopyTokenBasedSet can only be used for IPermission and PermissionList based TokenBasedSets" );
copySet.SetItem( i, obj );
}
}
return copySet;
}