[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 virtual LocalBuilder DeclareLocal(Type localType, bool pinned) { MethodBuilder methodBuilder = this.m_methodBuilder as MethodBuilder; if (methodBuilder == null) { throw new NotSupportedException(); } if (methodBuilder.IsTypeCreated()) { throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_TypeHasBeenCreated")); } if (localType == null) { throw new ArgumentNullException("localType"); } if (methodBuilder.m_bIsBaked) { throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_MethodBaked")); } this.m_localSignature.AddArgument(localType, pinned); LocalBuilder builder = new LocalBuilder(this.m_localCount, localType, methodBuilder, pinned); this.m_localCount++; return(builder); }
/// <summary>Sets the name and lexical scope of this local variable.</summary> /// <param name="name">The name of the local variable. </param> /// <param name="startOffset">The beginning offset of the lexical scope of the local variable. </param> /// <param name="endOffset">The ending offset of the lexical scope of the local variable. </param> /// <exception cref="T:System.InvalidOperationException">The containing type has been created with <see cref="M:System.Reflection.Emit.TypeBuilder.CreateType" />.-or- There is no symbolic writer defined for the containing module. </exception> /// <exception cref="T:System.NotSupportedException">This local is defined in a dynamic method, rather than in a method of a dynamic type.</exception> // Token: 0x060049F6 RID: 18934 RVA: 0x0010B4A8 File Offset: 0x001096A8 public void SetLocalSymInfo(string name, int startOffset, int endOffset) { MethodBuilder methodBuilder = this.m_methodBuilder as MethodBuilder; if (methodBuilder == null) { throw new NotSupportedException(); } ModuleBuilder moduleBuilder = (ModuleBuilder)methodBuilder.Module; if (methodBuilder.IsTypeCreated()) { throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_TypeHasBeenCreated")); } if (moduleBuilder.GetSymWriter() == null) { throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_NotADebugModule")); } SignatureHelper fieldSigHelper = SignatureHelper.GetFieldSigHelper(moduleBuilder); fieldSigHelper.AddArgument(this.m_localType); int num; byte[] sourceArray = fieldSigHelper.InternalGetSignature(out num); byte[] array = new byte[num - 1]; Array.Copy(sourceArray, 1, array, 0, num - 1); int currentActiveScopeIndex = methodBuilder.GetILGenerator().m_ScopeTree.GetCurrentActiveScopeIndex(); if (currentActiveScopeIndex == -1) { methodBuilder.m_localSymInfo.AddLocalSymInfo(name, array, this.m_localIndex, startOffset, endOffset); return; } methodBuilder.GetILGenerator().m_ScopeTree.AddLocalSymInfoToCurrentScope(name, array, this.m_localIndex, startOffset, endOffset); }
/// <summary>设置该局部变量的名称和词法范围。</summary> /// <param name="name">局部变量的名称。</param> /// <param name="startOffset">局部变量词法范围的开始偏移量。</param> /// <param name="endOffset">局部变量词法范围的结束偏移量。</param> /// <exception cref="T:System.InvalidOperationException">已经用 <see cref="M:System.Reflection.Emit.TypeBuilder.CreateType" /> 创建了该包含类型。- 或 -没有为包含模块定义的符号编写器。</exception> /// <exception cref="T:System.NotSupportedException">此局部变量是使用动态方法(而不是动态类型的方法)来定义的。</exception> public void SetLocalSymInfo(string name, int startOffset, int endOffset) { MethodBuilder methodBuilder = this.m_methodBuilder as MethodBuilder; if ((MethodInfo)methodBuilder == (MethodInfo)null) { throw new NotSupportedException(); } ModuleBuilder moduleBuilder = (ModuleBuilder)methodBuilder.Module; if (methodBuilder.IsTypeCreated()) { throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_TypeHasBeenCreated")); } if (moduleBuilder.GetSymWriter() == null) { throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_NotADebugModule")); } SignatureHelper fieldSigHelper = SignatureHelper.GetFieldSigHelper((Module)moduleBuilder); Type clsArgument = this.m_localType; fieldSigHelper.AddArgument(clsArgument); int num; // ISSUE: explicit reference operation // ISSUE: variable of a reference type int& length1 = @num; byte[] signature1 = fieldSigHelper.InternalGetSignature(length1); byte[] signature2 = new byte[num - 1]; int sourceIndex = 1; byte[] numArray = signature2; int destinationIndex = 0; int length2 = num - 1; Array.Copy((Array)signature1, sourceIndex, (Array)numArray, destinationIndex, length2); if (methodBuilder.GetILGenerator().m_ScopeTree.GetCurrentActiveScopeIndex() == -1) { methodBuilder.m_localSymInfo.AddLocalSymInfo(name, signature2, this.m_localIndex, startOffset, endOffset); } else { methodBuilder.GetILGenerator().m_ScopeTree.AddLocalSymInfoToCurrentScope(name, signature2, this.m_localIndex, startOffset, endOffset); } }
public void SetLocalSymInfo(String name, int startOffset, int endOffset) { ModuleBuilder dynMod; SignatureHelper sigHelp; int sigLength; byte[] signature; byte[] mungedSig; int index; MethodBuilder methodBuilder = m_methodBuilder as MethodBuilder; if (methodBuilder == null) { // it's a light code gen entity throw new NotSupportedException(); } dynMod = (ModuleBuilder)methodBuilder.Module; if (methodBuilder.IsTypeCreated()) { // cannot change method after its containing type has been created throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_TypeHasBeenCreated")); } // set the name and range of offset for the local if (dynMod.GetSymWriter() == null) { // cannot set local name if not debug module throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_NotADebugModule")); } sigHelp = SignatureHelper.GetFieldSigHelper(dynMod); sigHelp.AddArgument(m_localType); signature = sigHelp.InternalGetSignature(out sigLength); // The symbol store doesn't want the calling convention on the // front of the signature, but InternalGetSignature returns // the callinging convention. So we strip it off. This is a // bit unfortunate, since it means that we need to allocate // yet another array of bytes... mungedSig = new byte[sigLength - 1]; Array.Copy(signature, 1, mungedSig, 0, sigLength - 1); index = methodBuilder.GetILGenerator().m_ScopeTree.GetCurrentActiveScopeIndex(); if (index == -1) { // top level scope information is kept with methodBuilder methodBuilder.m_localSymInfo.AddLocalSymInfo( name, mungedSig, m_localIndex, startOffset, endOffset); } else { methodBuilder.GetILGenerator().m_ScopeTree.AddLocalSymInfoToCurrentScope( name, mungedSig, m_localIndex, startOffset, endOffset); } }