public IPermission Intersect(IPermission target)
{
if (target == null)
{
return null;
}
else if (!VerifyType(target))
{
throw new ArgumentException(SR.Argument_WrongType, GetType().FullName);
}
else if (IsUnrestricted())
{
return target.Copy();
}
PrincipalPermission operand = (PrincipalPermission)target;
if (operand.IsUnrestricted())
{
return Copy();
}
List<IDRole> idroles = null;
foreach (IDRole idRole in _idArray)
{
foreach (IDRole operandIdRole in operand._idArray)
{
if (operandIdRole.Authenticated == idRole.Authenticated)
{
string newID = string.Empty;
string newRole = string.Empty;
bool newAuthenticated = operandIdRole.Authenticated;
bool addToNewIDRoles = false;
if (operandIdRole.ID == null || idRole.ID == null || idRole.ID.Equals(operandIdRole.ID))
{
newID = operandIdRole.ID == null ? idRole.ID : operandIdRole.ID;
addToNewIDRoles = true;
}
if (operandIdRole.Role == null || idRole.Role == null || idRole.Role.Equals(operandIdRole.Role))
{
newRole = operandIdRole.Role == null ? idRole.Role : operandIdRole.Role;
addToNewIDRoles = true;
}
if (addToNewIDRoles)
{
if (idroles == null)
idroles = new List<IDRole>();
idroles.Add(new IDRole(newAuthenticated, newID, newRole));
}
}
}
}
return (idroles == null) ? null : new PrincipalPermission(idroles.ToArray());
}