public Intersect ( IPermission target ) : IPermission | ||
target | IPermission | |
return | IPermission |
public override IPermission Intersect(IPermission target)
{
if (target == null)
return null;
else if (!VerifyType(target))
{
throw new
ArgumentException(
String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Argument_WrongType"), this.GetType().FullName)
);
}
IsolatedStorageFilePermission operand = (IsolatedStorageFilePermission)target;
if(operand.IsUnrestricted())
return Copy();
else if(IsUnrestricted())
return target.Copy();
IsolatedStorageFilePermission intersection;
intersection = new IsolatedStorageFilePermission( PermissionState.None );
intersection.m_userQuota = min(m_userQuota,operand.m_userQuota);
intersection.m_machineQuota = min(m_machineQuota,operand.m_machineQuota);
intersection.m_expirationDays = min(m_expirationDays,operand.m_expirationDays);
intersection.m_permanentData = m_permanentData && operand.m_permanentData;
intersection.m_allowed = (IsolatedStorageContainment)min((long)m_allowed,(long)operand.m_allowed);
if ((intersection.m_userQuota == 0) &&
(intersection.m_machineQuota == 0) &&
(intersection.m_expirationDays == 0) &&
(intersection.m_permanentData == false) &&
(intersection.m_allowed == IsolatedStorageContainment.None))
return null;
return intersection;
}
public void Intersect () { IsolatedStorageFilePermission empty = new IsolatedStorageFilePermission (PermissionState.None); IsolatedStorageFilePermission intersect = (IsolatedStorageFilePermission)empty.Intersect (null); Assert.IsNull (intersect, "empty N null"); intersect = (IsolatedStorageFilePermission)empty.Intersect (empty); Assert.IsNull (intersect, "empty N empty"); IsolatedStorageFilePermission unrestricted = new IsolatedStorageFilePermission (PermissionState.Unrestricted); intersect = (IsolatedStorageFilePermission)unrestricted.Intersect (null); Assert.IsNull (intersect, "unrestricted N null"); intersect = (IsolatedStorageFilePermission)unrestricted.Intersect (empty); Assert.IsNotNull (intersect, "unrestricted N empty"); intersect = (IsolatedStorageFilePermission)unrestricted.Intersect (unrestricted); Assert.IsNotNull (intersect, "unrestricted N unrestricted"); }