public override IPermission Intersect(IPermission target) { RegistryPermission rp = Cast(target); if (rp == null) { return(null); } if (IsUnrestricted()) { return(rp.Copy()); } if (rp.IsUnrestricted()) { return(Copy()); } RegistryPermission result = new RegistryPermission(PermissionState.None); IntersectKeys(createList, rp.createList, result.createList); IntersectKeys(readList, rp.readList, result.readList); IntersectKeys(writeList, rp.writeList, result.writeList); return(result.IsEmpty() ? null : result); }
public void PermissionStateUnrestricted () { RegistryPermission ep = new RegistryPermission (PermissionState.Unrestricted); Assert.IsNotNull (ep, "RegistryPermission(PermissionState.Unrestricted)"); Assert.IsTrue (ep.IsUnrestricted (), "IsUnrestricted"); RegistryPermission copy = (RegistryPermission)ep.Copy (); Assert.AreEqual (ep.IsUnrestricted (), copy.IsUnrestricted (), "Copy.IsUnrestricted"); SecurityElement se = ep.ToXml (); Assert.AreEqual ("true", se.Attribute ("Unrestricted"), "ToXml-Unrestricted"); }
public void PermissionStateUnrestricted () { RegistryPermission ep = new RegistryPermission (PermissionState.Unrestricted); AssertNotNull ("RegistryPermission(PermissionState.Unrestricted)", ep); Assert ("IsUnrestricted", ep.IsUnrestricted ()); RegistryPermission copy = (RegistryPermission)ep.Copy (); AssertEquals ("Copy.IsUnrestricted", ep.IsUnrestricted (), copy.IsUnrestricted ()); SecurityElement se = ep.ToXml (); AssertEquals ("ToXml-Unrestricted", "true", se.Attribute ("Unrestricted")); }
public void PermissionStateNone () { RegistryPermission ep = new RegistryPermission (PermissionState.None); Assert.IsNotNull (ep, "RegistryPermission(PermissionState.None)"); Assert.IsTrue (!ep.IsUnrestricted (), "IsUnrestricted"); RegistryPermission copy = (RegistryPermission)ep.Copy (); Assert.AreEqual (ep.IsUnrestricted (), copy.IsUnrestricted (), "Copy.IsUnrestricted"); SecurityElement se = ep.ToXml (); Assert.IsTrue (se.Attribute ("class").StartsWith (className), "ToXml-class"); Assert.AreEqual ("1", se.Attribute ("version"), "ToXml-version"); }
public void PermissionStateNone () { RegistryPermission ep = new RegistryPermission (PermissionState.None); AssertNotNull ("RegistryPermission(PermissionState.None)", ep); Assert ("IsUnrestricted", !ep.IsUnrestricted ()); RegistryPermission copy = (RegistryPermission)ep.Copy (); AssertEquals ("Copy.IsUnrestricted", ep.IsUnrestricted (), copy.IsUnrestricted ()); SecurityElement se = ep.ToXml (); Assert ("ToXml-class", se.Attribute ("class").StartsWith (className)); AssertEquals ("ToXml-version", "1", se.Attribute ("version")); }
/// <summary>Creates and returns a permission that is the intersection of the current permission and the specified permission.</summary> /// <returns>A new permission that represents the intersection of the current permission and the specified permission. This new permission is null if the intersection is empty.</returns> /// <param name="target">A permission to intersect with the current permission. It must be of the same type as the current permission. </param> /// <exception cref="T:System.ArgumentException">The <paramref name="target" /> parameter is not null and is not of the same type as the current permission. </exception> public override IPermission Intersect(IPermission target) { RegistryPermission registryPermission = this.Cast(target); if (registryPermission == null) { return(null); } if (this.IsUnrestricted()) { return(registryPermission.Copy()); } if (registryPermission.IsUnrestricted()) { return(this.Copy()); } RegistryPermission registryPermission2 = new RegistryPermission(PermissionState.None); this.IntersectKeys(this.createList, registryPermission.createList, registryPermission2.createList); this.IntersectKeys(this.readList, registryPermission.readList, registryPermission2.readList); this.IntersectKeys(this.writeList, registryPermission.writeList, registryPermission2.writeList); return((!registryPermission2.IsEmpty()) ? registryPermission2 : null); }