public void Derestricted () { ReflectionPermission p = new ReflectionPermission (PermissionState.Unrestricted); Assert.IsTrue (p.IsUnrestricted (), "IsUnrestricted"); p.Flags = ReflectionPermissionFlag.NoFlags; Assert.IsTrue (!p.IsUnrestricted (), "IsUnrestricted"); }
public void Derestricted () { ReflectionPermission p = new ReflectionPermission (PermissionState.Unrestricted); Assert ("IsUnrestricted", p.IsUnrestricted ()); p.Flags = ReflectionPermissionFlag.NoFlags; Assert ("IsUnrestricted", !p.IsUnrestricted ()); }
public void PermissionStateUnrestricted () { ReflectionPermission p = new ReflectionPermission (PermissionState.Unrestricted); AssertNotNull ("ReflectionPermission(PermissionState.Unrestricted)", p); Assert ("IsUnrestricted", p.IsUnrestricted ()); ReflectionPermission copy = (ReflectionPermission) p.Copy (); AssertEquals ("Copy.IsUnrestricted", p.IsUnrestricted (), copy.IsUnrestricted ()); SecurityElement se = p.ToXml (); AssertEquals ("ToXml-Unrestricted", "true", (se.Attributes ["Unrestricted"] as string)); }
public void PermissionStateUnrestricted () { ReflectionPermission p = new ReflectionPermission (PermissionState.Unrestricted); Assert.IsNotNull (p, "ReflectionPermission(PermissionState.Unrestricted)"); Assert.IsTrue (p.IsUnrestricted (), "IsUnrestricted"); ReflectionPermission copy = (ReflectionPermission) p.Copy (); Assert.AreEqual (p.IsUnrestricted (), copy.IsUnrestricted (), "Copy.IsUnrestricted"); SecurityElement se = p.ToXml (); Assert.AreEqual ("true", (se.Attributes ["Unrestricted"] as string), "ToXml-Unrestricted"); }
public void PermissionStateNone () { ReflectionPermission p = new ReflectionPermission (PermissionState.None); Assert.IsNotNull (p, "ReflectionPermission(PermissionState.None)"); Assert.IsTrue (!p.IsUnrestricted (), "IsUnrestricted"); ReflectionPermission copy = (ReflectionPermission) p.Copy (); Assert.AreEqual (p.IsUnrestricted (), copy.IsUnrestricted (), "Copy.IsUnrestricted"); SecurityElement se = p.ToXml (); Assert.IsTrue ((se.Attributes ["class"] as string).StartsWith (className), "ToXml-class"); Assert.AreEqual ("1", (se.Attributes ["version"] as string), "ToXml-version"); }
public void PermissionStateNone () { ReflectionPermission p = new ReflectionPermission (PermissionState.None); AssertNotNull ("ReflectionPermission(PermissionState.None)", p); Assert ("IsUnrestricted", !p.IsUnrestricted ()); ReflectionPermission copy = (ReflectionPermission) p.Copy (); AssertEquals ("Copy.IsUnrestricted", p.IsUnrestricted (), copy.IsUnrestricted ()); SecurityElement se = p.ToXml (); Assert ("ToXml-class", (se.Attributes ["class"] as string).StartsWith (className)); AssertEquals ("ToXml-version", "1", (se.Attributes ["version"] as string)); }
/// <summary>Determines whether the current permission is a subset of the specified permission.</summary> /// <returns>true if the current permission is a subset of the specified permission; otherwise, false.</returns> /// <param name="target">A permission that is to be tested for the subset relationship. This permission 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 bool IsSubsetOf(IPermission target) { ReflectionPermission reflectionPermission = this.Cast(target); if (reflectionPermission == null) { return(this.flags == ReflectionPermissionFlag.NoFlags); } if (this.IsUnrestricted()) { return(reflectionPermission.IsUnrestricted()); } return(reflectionPermission.IsUnrestricted() || (this.flags & reflectionPermission.Flags) == this.flags); }
/// <summary>Determines whether the current permission is a subset of the specified permission.</summary> /// <param name="target">A permission that is to be tested for the subset relationship. This permission must be of the same type as the current permission. </param> /// <returns> /// <see langword="true" /> if the current permission is a subset of the specified permission; otherwise, <see langword="false" />.</returns> /// <exception cref="T:System.ArgumentException">The <paramref name="target" /> parameter is not <see langword="null" /> and is not of the same type as the current permission. </exception> // Token: 0x060025F3 RID: 9715 RVA: 0x00088858 File Offset: 0x00086A58 public override bool IsSubsetOf(IPermission target) { if (target == null) { return(this.m_flags == ReflectionPermissionFlag.NoFlags); } bool result; try { ReflectionPermission reflectionPermission = (ReflectionPermission)target; if (reflectionPermission.IsUnrestricted()) { result = true; } else if (this.IsUnrestricted()) { result = false; } else { result = ((this.m_flags & ~reflectionPermission.m_flags) == ReflectionPermissionFlag.NoFlags); } } catch (InvalidCastException) { throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", new object[] { base.GetType().FullName })); } return(result); }
public void TypeInformation () { ReflectionPermission p = new ReflectionPermission (ReflectionPermissionFlag.TypeInformation); Assert.IsTrue (!p.IsUnrestricted (), "IsUnrestricted"); SecurityElement se = p.ToXml (); Assert.AreEqual ("TypeInformation", (se.Attributes ["Flags"] as string), "ToXml-Flags=TypeInformation"); }
// // IPermission implementation // public override IPermission Union(IPermission other) { if (other == null) { return(this.Copy()); } else if (!VerifyType(other)) { throw new ArgumentException( Environment.GetResourceString("Argument_WrongType", this.GetType().FullName) ); } ReflectionPermission operand = (ReflectionPermission)other; if (this.IsUnrestricted() || operand.IsUnrestricted()) { return(new ReflectionPermission(PermissionState.Unrestricted)); } else { ReflectionPermissionFlag flag_union = (ReflectionPermissionFlag)(m_flags | operand.m_flags); return(new ReflectionPermission(flag_union)); } }
public void MemberAccess () { ReflectionPermission p = new ReflectionPermission (ReflectionPermissionFlag.MemberAccess); Assert ("IsUnrestricted", !p.IsUnrestricted ()); SecurityElement se = p.ToXml (); AssertEquals ("ToXml-Flags=MemberAccess", "MemberAccess", (se.Attributes ["Flags"] as string)); }
public void MemberAccess () { ReflectionPermission p = new ReflectionPermission (ReflectionPermissionFlag.MemberAccess); Assert.IsTrue (!p.IsUnrestricted (), "IsUnrestricted"); SecurityElement se = p.ToXml (); Assert.AreEqual ("MemberAccess", (se.Attributes ["Flags"] as string), "ToXml-Flags=MemberAccess"); }
/// <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) { ReflectionPermission reflectionPermission = this.Cast(target); if (reflectionPermission == null) { return(null); } if (this.IsUnrestricted()) { if (reflectionPermission.Flags == ReflectionPermissionFlag.NoFlags) { return(null); } return(reflectionPermission.Copy()); } else { if (!reflectionPermission.IsUnrestricted()) { ReflectionPermission reflectionPermission2 = (ReflectionPermission)reflectionPermission.Copy(); reflectionPermission2.Flags &= this.flags; return((reflectionPermission2.Flags != ReflectionPermissionFlag.NoFlags) ? reflectionPermission2 : null); } if (this.flags == ReflectionPermissionFlag.NoFlags) { return(null); } return(this.Copy()); } }
public override bool IsSubsetOf(IPermission target) { bool flag; if (target == null) { return(this.m_flags == ReflectionPermissionFlag.NoFlags); } try { ReflectionPermission permission = (ReflectionPermission)target; if (permission.IsUnrestricted()) { return(true); } if (this.IsUnrestricted()) { return(false); } flag = (this.m_flags & ~permission.m_flags) == ReflectionPermissionFlag.NoFlags; } catch (InvalidCastException) { throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", new object[] { base.GetType().FullName })); } return(flag); }
public override bool IsSubsetOf(IPermission target) { if (target == null) { return(m_flags == ReflectionPermissionFlag.NoFlags); } try { ReflectionPermission operand = (ReflectionPermission)target; if (operand.IsUnrestricted()) { return(true); } else if (this.IsUnrestricted()) { return(false); } else { return((((int)this.m_flags) & ~((int)operand.m_flags)) == 0); } } catch (InvalidCastException) { throw new ArgumentException( Environment.GetResourceString("Argument_WrongType", this.GetType().FullName) ); } }
public override bool IsSubsetOf(IPermission target) { ReflectionPermission rp = Cast(target); if (rp == null) { return(flags == ReflectionPermissionFlag.NoFlags); } if (IsUnrestricted()) { return(rp.IsUnrestricted()); } else if (rp.IsUnrestricted()) { return(true); } return((flags & rp.Flags) == flags); }
/// <summary>Creates a permission that is the union of the current permission and the specified permission.</summary> /// <returns>A new permission that represents the union of the current permission and the specified permission.</returns> /// <param name="other">A permission to combine with the current permission. It must be of the same type as the current permission. </param> /// <exception cref="T:System.ArgumentException">The <paramref name="other" /> parameter is not null and is not of the same type as the current permission. </exception> public override IPermission Union(IPermission other) { ReflectionPermission reflectionPermission = this.Cast(other); if (other == null) { return(this.Copy()); } if (this.IsUnrestricted() || reflectionPermission.IsUnrestricted()) { return(new ReflectionPermission(PermissionState.Unrestricted)); } ReflectionPermission reflectionPermission2 = (ReflectionPermission)reflectionPermission.Copy(); reflectionPermission2.Flags |= this.flags; return(reflectionPermission2); }
public override IPermission Union(IPermission other) { if (other == null) { return(this.Copy()); } if (!base.VerifyType(other)) { throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", new object[] { base.GetType().FullName })); } ReflectionPermission permission = (ReflectionPermission)other; if (this.IsUnrestricted() || permission.IsUnrestricted()) { return(new ReflectionPermission(PermissionState.Unrestricted)); } return(new ReflectionPermission(this.m_flags | permission.m_flags)); }
public override IPermission Union(IPermission other) { ReflectionPermission rp = Cast(other); if (other == null) { return(Copy()); } if (IsUnrestricted() || rp.IsUnrestricted()) { return(new ReflectionPermission(PermissionState.Unrestricted)); } ReflectionPermission p = (ReflectionPermission)rp.Copy(); p.Flags |= flags; return(p); }
public override IPermission Intersect(IPermission target) { ReflectionPermission rp = Cast(target); if (rp == null) { return(null); } if (IsUnrestricted()) { if (rp.Flags == ReflectionPermissionFlag.NoFlags) { return(null); } else { return(rp.Copy()); } } if (rp.IsUnrestricted()) { if (flags == ReflectionPermissionFlag.NoFlags) { return(null); } else { return(Copy()); } } ReflectionPermission p = (ReflectionPermission)rp.Copy(); p.Flags &= flags; return((p.Flags == ReflectionPermissionFlag.NoFlags) ? null : p); }
/// <summary>确定当前权限是否为指定权限的子集。</summary> /// <returns>如果当前权限是指定权限的子集,则为 true;否则为 false。</returns> /// <param name="target">将要测试子集关系的权限。此权限必须与当前权限属于同一类型。</param> /// <exception cref="T:System.ArgumentException"> /// <paramref name="target" /> 参数不是 null,而且与当前权限不是同一类型。</exception> public override bool IsSubsetOf(IPermission target) { if (target == null) { return(this.m_flags == ReflectionPermissionFlag.NoFlags); } try { ReflectionPermission reflectionPermission = (ReflectionPermission)target; if (reflectionPermission.IsUnrestricted()) { return(true); } if (this.IsUnrestricted()) { return(false); } return((this.m_flags & ~reflectionPermission.m_flags) == ReflectionPermissionFlag.NoFlags); } catch (InvalidCastException ex) { throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", (object)this.GetType().FullName)); } }
public void Flags () { ReflectionPermission p = new ReflectionPermission (PermissionState.None); Assert.IsTrue (!p.IsUnrestricted (), "Flags(default).IsUnrestricted"); p.Flags = ReflectionPermissionFlag.NoFlags; Assert.IsTrue (!p.IsUnrestricted (), "Flags(NoFlags).IsUnrestricted"); p.Flags = ReflectionPermissionFlag.TypeInformation; Assert.IsTrue (!p.IsUnrestricted (), "Flags(TypeInformation).IsUnrestricted"); p.Flags = ReflectionPermissionFlag.MemberAccess; Assert.IsTrue (!p.IsUnrestricted (), "Flags(MemberAccess).IsUnrestricted"); p.Flags = ReflectionPermissionFlag.ReflectionEmit; Assert.IsTrue (!p.IsUnrestricted (), "Flags(ReflectionEmit).IsUnrestricted"); p.Flags = ReflectionPermissionFlag.AllFlags; Assert.IsTrue (p.IsUnrestricted (), "Flags(AllFlags).IsUnrestricted"); }
public void ReflectionEmit () { ReflectionPermission p = new ReflectionPermission (ReflectionPermissionFlag.ReflectionEmit); Assert ("IsUnrestricted", !p.IsUnrestricted ()); SecurityElement se = p.ToXml (); AssertEquals ("ToXml-Flags=ReflectionEmit", "ReflectionEmit", (se.Attributes ["Flags"] as string)); }
public void ReflectionEmit () { ReflectionPermission p = new ReflectionPermission (ReflectionPermissionFlag.ReflectionEmit); Assert.IsTrue (!p.IsUnrestricted (), "IsUnrestricted"); SecurityElement se = p.ToXml (); Assert.AreEqual ("ReflectionEmit", (se.Attributes ["Flags"] as string), "ToXml-Flags=ReflectionEmit"); }
public void AllFlags () { ReflectionPermission p = new ReflectionPermission (ReflectionPermissionFlag.AllFlags); Assert ("IsUnrestricted", p.IsUnrestricted ()); SecurityElement se = p.ToXml (); AssertEquals ("ToXml-Unrestricted", "true", (se.Attributes ["Unrestricted"] as string)); }
public void AllFlags () { ReflectionPermission p = new ReflectionPermission (ReflectionPermissionFlag.AllFlags); Assert.IsTrue (p.IsUnrestricted (), "IsUnrestricted"); SecurityElement se = p.ToXml (); Assert.AreEqual ("true", (se.Attributes ["Unrestricted"] as string), "ToXml-Unrestricted"); }