// Form the union of this security set and another.
public virtual PermissionSet Union(PermissionSet other)
{
PermissionSet pset;
if (other == null)
{
pset = new PermissionSet(state);
}
else if (IsUnrestricted() || other.IsUnrestricted())
{
pset = new PermissionSet(PermissionState.Unrestricted);
}
else
{
pset = new PermissionSet(PermissionState.None);
}
foreach (IPermission perm in permissions)
{
pset.AddPermission(perm);
}
if (other == null || other.IsEmpty())
{
return(pset);
}
IEnumerator e = other.GetEnumerator();
IPermission permOther, permThis;
int index;
while (e.MoveNext())
{
permOther = (e.Current as IPermission);
if (permOther != null)
{
index = pset.FindPermission(permOther.GetType());
if (index != -1)
{
permThis = (IPermission)(permissions[index]);
permThis = permThis.Union(permOther);
if (permThis != null)
{
pset.SetPermission(permThis);
}
}
else
{
pset.AddPermission(permOther);
}
}
}
return(pset);
}