[System.Security.SecuritySafeCritical] // auto-generated public void AddDeclarativeSecurity(SecurityAction action, PermissionSet pset) { if (pset == null) { throw new ArgumentNullException(nameof(pset)); } #pragma warning disable 618 if (!Enum.IsDefined(typeof(SecurityAction), action) || action == SecurityAction.RequestMinimum || action == SecurityAction.RequestOptional || action == SecurityAction.RequestRefuse) { throw new ArgumentOutOfRangeException(nameof(action)); } #pragma warning restore 618 Contract.EndContractBlock(); // Cannot add declarative security after type is created. if (m_methodBuilder.IsTypeCreated()) { throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_TypeHasBeenCreated")); } // Translate permission set into serialized format (use standard binary serialization). byte[] blob = pset.EncodeXml(); // Write the blob into the metadata. TypeBuilder.AddDeclarativeSecurity(GetModuleBuilder().GetNativeHandle(), GetToken().Token, action, blob, blob.Length); }
public void AddDeclarativeSecurity(SecurityAction action, PermissionSet pset) { if (pset == null) { throw new ArgumentNullException("pset"); } if ((!Enum.IsDefined(typeof(SecurityAction), action) || (action == SecurityAction.RequestMinimum)) || ((action == SecurityAction.RequestOptional) || (action == SecurityAction.RequestRefuse))) { throw new ArgumentOutOfRangeException("action"); } if (this.m_methodBuilder.IsTypeCreated()) { throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_TypeHasBeenCreated")); } byte[] blob = pset.EncodeXml(); TypeBuilder.AddDeclarativeSecurity(this.GetModuleBuilder().GetNativeHandle(), this.GetToken().Token, action, blob, blob.Length); }
public void AddDeclarativeSecurity(SecurityAction action, PermissionSet pset) { if (pset == null) { throw new ArgumentNullException("pset"); } this.ThrowIfGeneric(); if ((!Enum.IsDefined(typeof(SecurityAction), action) || (action == SecurityAction.RequestMinimum)) || ((action == SecurityAction.RequestOptional) || (action == SecurityAction.RequestRefuse))) { throw new ArgumentOutOfRangeException("action"); } this.m_containingType.ThrowIfCreated(); byte[] blob = null; int cb = 0; if (!pset.IsEmpty()) { blob = pset.EncodeXml(); cb = blob.Length; } TypeBuilder.AddDeclarativeSecurity(this.m_module.GetNativeHandle(), this.MetadataTokenInternal, action, blob, cb); }
public void AddDeclarativeSecurity(SecurityAction action, PermissionSet pset) { if (pset == null) { throw new ArgumentNullException("pset"); } if (!Enum.IsDefined(typeof(SecurityAction), (object)action) || action == SecurityAction.RequestMinimum || (action == SecurityAction.RequestOptional || action == SecurityAction.RequestRefuse)) { throw new ArgumentOutOfRangeException("action"); } if (this.m_methodBuilder.IsTypeCreated()) { throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_TypeHasBeenCreated")); } byte[] numArray = pset.EncodeXml(); RuntimeModule nativeHandle = this.GetModuleBuilder().GetNativeHandle(); int token = this.GetToken().Token; int num = (int)action; byte[] blob = numArray; int length = blob.Length; TypeBuilder.AddDeclarativeSecurity(nativeHandle, token, (SecurityAction)num, blob, length); }
private void Visit(ITypeDefinition typeDefinition, TypeBuilder typeBuilder) { if (typeDefinition.HasDeclarativeSecurity) { foreach (var securityAttribute in typeDefinition.SecurityAttributes) typeBuilder.AddDeclarativeSecurity(GetSecurityAction(securityAttribute), GetPermissionSet(securityAttribute)); } foreach (var implementedInterface in typeDefinition.Interfaces) typeBuilder.AddInterfaceImplementation(this.loader.mapper.GetType(implementedInterface)); foreach (var explicitOverride in typeDefinition.ExplicitImplementationOverrides) { typeBuilder.DefineMethodOverride((MethodInfo)this.loader.mapper.GetMethod(explicitOverride.ImplementingMethod), (MethodInfo)this.loader.mapper.GetMethod(explicitOverride.ImplementedMethod)); } if (typeDefinition.IsGeneric) { foreach (var genericParameter in typeDefinition.GenericParameters) this.Visit(genericParameter); } foreach (var customAttribute in typeDefinition.Attributes) { var customAttributeBuilder = this.GetCustomAttributeBuilder(customAttribute); typeBuilder.SetCustomAttribute(customAttributeBuilder); } foreach (var baseType in typeDefinition.BaseClasses) { typeBuilder.SetParent(this.loader.mapper.GetType(baseType)); break; } }