using System; using System.Runtime.InteropServices; namespace System.Security.Permissions { /// Controls access to non-public types and members through the APIs. Controls some features of the APIs. // Token: 0x02000561 RID: 1377 [ComVisible(true)] [Serializable] public sealed class ReflectionPermission : CodeAccessPermission, IBuiltInPermission, IUnrestrictedPermission { /// Initializes a new instance of the class with either fully restricted or unrestricted permission as specified. /// One of the values. /// The parameter is not a valid value of . // Token: 0x0600324B RID: 12875 RVA: 0x000ACB68 File Offset: 0x000AAD68 public ReflectionPermission(PermissionState state) { if (CodeAccessPermission.CheckPermissionState(state, true) == PermissionState.Unrestricted) { this.flags = ReflectionPermissionFlag.AllFlags; } else { this.flags = ReflectionPermissionFlag.NoFlags; } } /// Initializes a new instance of the class with the specified access. /// One of the values. /// The parameter is not a valid value of . // Token: 0x0600324C RID: 12876 RVA: 0x000ACB9C File Offset: 0x000AAD9C public ReflectionPermission(ReflectionPermissionFlag flag) { this.Flags = flag; } // Token: 0x0600324D RID: 12877 RVA: 0x000ACBAC File Offset: 0x000AADAC int IBuiltInPermission.GetTokenIndex() { return 4; } /// Gets or sets the type of reflection allowed for the current permission. /// The set flags for the current permission. /// An attempt is made to set this property to an invalid value. See for the valid values. // Token: 0x170009E1 RID: 2529 // (get) Token: 0x0600324E RID: 12878 RVA: 0x000ACBB0 File Offset: 0x000AADB0 // (set) Token: 0x0600324F RID: 12879 RVA: 0x000ACBB8 File Offset: 0x000AADB8 public ReflectionPermissionFlag Flags { get { return this.flags; } set { if ((value & (ReflectionPermissionFlag.TypeInformation | ReflectionPermissionFlag.MemberAccess | ReflectionPermissionFlag.ReflectionEmit | ReflectionPermissionFlag.RestrictedMemberAccess)) != value) { string text = string.Format(Locale.GetText("Invalid flags {0}"), value); throw new ArgumentException(text, "ReflectionPermissionFlag"); } this.flags = value; } } /// Creates and returns an identical copy of the current permission. /// A copy of the current permission. // Token: 0x06003250 RID: 12880 RVA: 0x000ACBF8 File Offset: 0x000AADF8 public override IPermission Copy() { return new ReflectionPermission(this.flags); } /// Reconstructs a permission with a specified state from an XML encoding. /// The XML encoding to use to reconstruct the permission. /// The parameter is null. /// The parameter is not a valid permission element.-or- The parameter's version number is not valid. // Token: 0x06003251 RID: 12881 RVA: 0x000ACC08 File Offset: 0x000AAE08 public override void FromXml(SecurityElement esd) { CodeAccessPermission.CheckSecurityElement(esd, "esd", 1, 1); if (CodeAccessPermission.IsUnrestricted(esd)) { this.flags = ReflectionPermissionFlag.AllFlags; } else { this.flags = ReflectionPermissionFlag.NoFlags; string text = esd.Attributes["Flags"] as string; if (text.IndexOf("MemberAccess") >= 0) { this.flags |= ReflectionPermissionFlag.MemberAccess; } if (text.IndexOf("ReflectionEmit") >= 0) { this.flags |= ReflectionPermissionFlag.ReflectionEmit; } if (text.IndexOf("TypeInformation") >= 0) { this.flags |= ReflectionPermissionFlag.TypeInformation; } } } /// Creates and returns a permission that is the intersection of the current permission and the specified permission. /// 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. /// A permission to intersect with the current permission. It must be of the same type as the current permission. /// The parameter is not null and is not of the same type as the current permission. // Token: 0x06003252 RID: 12882 RVA: 0x000ACCB4 File Offset: 0x000AAEB4 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(); } } /// Determines whether the current permission is a subset of the specified permission. /// true if the current permission is a subset of the specified permission; otherwise, false. /// A permission that is to be tested for the subset relationship. This permission must be of the same type as the current permission. /// The parameter is not null and is not of the same type as the current permission. // Token: 0x06003253 RID: 12883 RVA: 0x000ACD40 File Offset: 0x000AAF40 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; } /// Returns a value indicating whether the current permission is unrestricted. /// true if the current permission is unrestricted; otherwise, false. // Token: 0x06003254 RID: 12884 RVA: 0x000ACD9C File Offset: 0x000AAF9C public bool IsUnrestricted() { return this.flags == ReflectionPermissionFlag.AllFlags; } /// Creates an XML encoding of the permission and its current state. /// An XML encoding of the permission, including any state information. // Token: 0x06003255 RID: 12885 RVA: 0x000ACDA8 File Offset: 0x000AAFA8 public override SecurityElement ToXml() { SecurityElement securityElement = base.Element(1); if (this.IsUnrestricted()) { securityElement.AddAttribute("Unrestricted", "true"); } else if (this.flags == ReflectionPermissionFlag.NoFlags) { securityElement.AddAttribute("Flags", "NoFlags"); } else if ((this.flags & ReflectionPermissionFlag.AllFlags) == ReflectionPermissionFlag.AllFlags) { securityElement.AddAttribute("Flags", "AllFlags"); } else { string text = string.Empty; if ((this.flags & ReflectionPermissionFlag.MemberAccess) == ReflectionPermissionFlag.MemberAccess) { text = "MemberAccess"; } if ((this.flags & ReflectionPermissionFlag.ReflectionEmit) == ReflectionPermissionFlag.ReflectionEmit) { if (text.Length > 0) { text += ", "; } text += "ReflectionEmit"; } if ((this.flags & ReflectionPermissionFlag.TypeInformation) == ReflectionPermissionFlag.TypeInformation) { if (text.Length > 0) { text += ", "; } text += "TypeInformation"; } securityElement.AddAttribute("Flags", text); } return securityElement; } /// Creates a permission that is the union of the current permission and the specified permission. /// A new permission that represents the union of the current permission and the specified permission. /// A permission to combine with the current permission. It must be of the same type as the current permission. /// The parameter is not null and is not of the same type as the current permission. // Token: 0x06003256 RID: 12886 RVA: 0x000ACEAC File Offset: 0x000AB0AC 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; } // Token: 0x06003257 RID: 12887 RVA: 0x000ACF0C File Offset: 0x000AB10C private ReflectionPermission Cast(IPermission target) { if (target == null) { return null; } ReflectionPermission reflectionPermission = target as ReflectionPermission; if (reflectionPermission == null) { CodeAccessPermission.ThrowInvalidPermission(target, typeof(ReflectionPermission)); } return reflectionPermission; } // Token: 0x040014A3 RID: 5283 private const int version = 1; // Token: 0x040014A4 RID: 5284 private ReflectionPermissionFlag flags; } }