We need you! We're working hard on the next version of Developer Fusion -
Let us know what you think we should be up to!
-
Expand
Microsoft.Win32
-
Expand
Microsoft.Win32.SafeHandles
-
Expand
System
-
Expand
System.Runtime.Hosting
-
Expand
System.Runtime.InteropServices
-
Expand
System.Runtime.CompilerServices
-
Expand
System.Collections
-
Expand
System.Collections.Generic
-
Expand
System.Collections.ObjectModel
-
Expand
System.Configuration.Assemblies
-
Expand
System.Diagnostics
-
Expand
System.Diagnostics.CodeAnalysis
-
Expand
System.Diagnostics.SymbolStore
-
Expand
System.Globalization
-
Expand
System.IO
-
Expand
System.IO.IsolatedStorage
-
Expand
System.Reflection
-
Expand
System.Reflection.Cache
-
Expand
System.Reflection.Emit
-
Expand
__ExceptionInfo
-
Expand
__ExceptionInstance
-
Expand
__FixupData
-
Expand
AssemblyBuilder
-
Expand
AssemblyBuilderAccess
-
Expand
AssemblyBuilderData
-
Expand
ConstructorBuilder
-
Expand
ConstructorOnTypeBuilderInstantiation
-
Expand
CustAttr
-
Expand
CustomAttributeBuilder
-
Expand
DestroyScout
-
Expand
DynamicILGenerator
-
AddSignature(byte)
-
AddStringLiteral(string)
-
BeginCatchBlock(Type)
-
BeginExceptFilterBlock()
-
BeginExceptionBlock()
-
BeginFaultBlock()
-
BeginFinallyBlock()
-
BeginScope()
-
DeclareLocal(Type, bool)
-
DynamicILGenerator(DynamicMethod, byte, int)
-
Emit(OpCode, ConstructorInfo)
-
Emit(OpCode, FieldInfo)
-
Emit(OpCode, MethodInfo)
-
Emit(OpCode, RuntimeFieldHandle)
-
Emit(OpCode, RuntimeMethodHandle)
-
Emit(OpCode, RuntimeMethodHandle, RuntimeTypeHandle)
-
Emit(OpCode, RuntimeTypeHandle)
-
Emit(OpCode, SignatureHelper)
-
Emit(OpCode, string)
-
Emit(OpCode, Type)
-
EmitCall(OpCode, MethodInfo, Type)
-
EmitCalli(OpCode, CallingConvention, Type, Type)
-
EmitCalli(OpCode, CallingConventions, Type, Type, Type)
-
EndExceptionBlock()
-
EndScope()
-
GetCallableMethod(void)
-
GetMaxStackSize()
-
GetMemberRefSignature(CallingConventions, Type, Type, Type)
-
GetMemberRefToken(MethodBase, Type)
-
MarkSequencePoint(ISymbolDocumentWriter, int, int, int, int)
-
UsingNamespace(string)
-
Expand
DynamicILInfo
-
Expand
DynamicMethod
-
Expand
DynamicResolver
-
Expand
DynamicScope
-
Expand
EmptyCAHolder
-
Expand
Entry
-
Expand
EnumBuilder
-
Expand
EventBuilder
-
Expand
EventToken
-
Expand
FieldBuilder
-
Expand
FieldOnTypeBuilderInstantiation
-
Expand
FieldToken
-
Expand
FlowControl
-
Expand
Format
-
Expand
GenericMethodInfo
-
Expand
GenericTypeParameterBuilder
-
Expand
ILGenerator
-
Expand
Label
-
Expand
LineNumberInfo
-
Expand
LocalBuilder
-
Expand
LocalSymInfo
-
Expand
MethodBuilder
-
Expand
MethodBuilderInstantiation
-
Expand
MethodOnTypeBuilderInstantiation
-
Expand
MethodRental
-
Expand
MethodToken
-
Expand
ModuleBuilder
-
Expand
ModuleBuilderData
-
Expand
OpCode
-
Expand
OpCodes
-
Expand
OpCodeType
-
Expand
OperandType
-
Expand
PackingSize
-
Expand
ParameterBuilder
-
Expand
ParameterToken
-
Expand
PEFileKinds
-
Expand
PropertyBuilder
-
Expand
PropertyToken
-
Expand
REDocument
-
Expand
ResWriterData
-
Expand
RTDynamicMethod
-
Expand
ScopeAction
-
Expand
ScopeTree
-
Expand
SecurityControlFlags
-
Expand
SignatureHelper
-
Expand
SignatureToken
-
Expand
StackBehaviour
-
Expand
StringToken
-
Expand
SymbolMethod
-
Expand
SymbolType
-
Expand
SymCustomAttr
-
Expand
TypeBuilder
-
Expand
TypeBuilderInstantiation
-
Expand
TypeKind
-
Expand
TypeNameBuilder
-
Expand
TypeToken
-
Expand
UnmanagedMarshal
-
Expand
VarArgMethod
-
Expand
System.Resources
-
Expand
System.Runtime
-
Expand
System.Runtime.InteropServices.Expando
-
Expand
System.Runtime.ConstrainedExecution
-
Expand
System.Runtime.Remoting.Activation
-
Expand
System.Runtime.Remoting.Messaging
-
Expand
System.Runtime.Remoting.Channels
-
Expand
System.Runtime.Remoting.Lifetime
-
Expand
System.Runtime.Remoting
-
Expand
System.Runtime.Remoting.Contexts
-
Expand
System.Runtime.Remoting.Proxies
-
Expand
System.Runtime.Remoting.Metadata
-
Expand
System.Runtime.Remoting.Metadata.W3cXsd2001
-
Expand
System.Runtime.Remoting.Services
-
Expand
System.Runtime.Serialization
-
Expand
System.Runtime.Serialization.Formatters
-
Expand
System.Runtime.Serialization.Formatters.Binary
-
Expand
System.Runtime.Versioning
-
Expand
System.Security
-
Expand
System.Security.Cryptography
-
Expand
System.Security.Cryptography.X509Certificates
-
Expand
System.Security.Permissions
-
Expand
System.Security.Policy
-
Expand
System.Security.Principal
-
Expand
System.Security.Util
-
Expand
System.Text
-
Expand
System.Threading
-
Expand
System.Runtime.Remoting.Channels.Http
-
Expand
System.Runtime.Remoting.Channels.Tcp
-
Expand
System.Runtime.Remoting.MetadataServices
-
Expand
System.Runtime.Serialization.Formatters.Soap.Xml
-
Expand
System.Runtime.Serialization.Formatters.Soap
-
Expand
Microsoft.Tools.Caspol
-
Expand
Microsoft.Tools.Build
-
Expand
Microsoft.CSharp
-
Expand
System.CodeDom
-
Expand
System.CodeDom.Compiler
-
Expand
System.Collections.Specialized
-
Expand
System.ComponentModel
-
Expand
System.ComponentModel.Design
-
Expand
System.ComponentModel.Design.Serialization
-
Expand
System.Configuration
-
Expand
System.Web
-
Expand
System.Configuration.Provider
-
Expand
System.Configuration.Internal
-
Expand
System.Internal
-
Expand
System.Windows.Forms
-
Expand
System.Net
-
Expand
System.Net.Sockets
-
Expand
System.Net.NetworkInformation
-
Expand
System.Net.ComImports
-
Expand
System.Net.Security
-
Expand
System.Net.Cache
-
Expand
System.Net.Configuration
-
Expand
System.Text.RegularExpressions
-
Expand
System.Tools
-
Expand
System.IO.Compression
-
Expand
System.IO.Ports
-
Expand
System.Security.AccessControl
-
Expand
System.Xml
-
Expand
System.Xml.XPath.DataBinding
-
Expand
System.Xml.Schema
-
Expand
System.Xml.Serialization
-
Expand
System.Xml.Serialization.Advanced
-
Expand
System.Xml.Serialization.Configuration
-
Expand
System.Xml.XPath
-
Expand
System.Xml.Xsl
-
Expand
System.Xml.Xsl.IlGen
-
Expand
System.Xml.Xsl.Qil
-
Expand
System.Xml.Xsl.Runtime
-
Expand
System.Xml.Xsl.XPath
-
Expand
System.Xml.Xsl.Xslt
-
Expand
System.Xml.Xsl.XsltOld
-
Expand
System.Xml.Xsl.XsltOld.Debugger
-
Expand
Microsoft.JScript
-
Expand
Microsoft.Vsa
-
Expand
Microsoft.JScript.Vsa
- namespace System.Reflection.Emit
- {
-
- using System;
- using System.Globalization;
- using TextWriter = System.IO.TextWriter;
- using System.Diagnostics.SymbolStore;
- using System.Runtime.InteropServices;
- using System.Reflection;
- using System.Collections;
- using System.Security.Permissions;
-
- internal class DynamicILGenerator : ILGenerator
- {
-
- internal DynamicScope m_scope;
- private int m_methodSigToken;
-
- unsafe internal DynamicILGenerator(DynamicMethod method, byte[] methodSignature, int size) : base(method, size)
- {
- m_scope = new DynamicScope();
- m_methodSigToken = m_scope.GetTokenFor(methodSignature);
- }
-
-
- unsafe internal RuntimeMethodHandle GetCallableMethod(void* module)
- {
- return new RuntimeMethodHandle(ModuleHandle.GetDynamicMethod(module, m_methodBuilder.Name, (byte[])m_scope[m_methodSigToken], new DynamicResolver(this)));
- }
-
-
-
- public override LocalBuilder DeclareLocal(Type localType, bool pinned)
- {
- LocalBuilder localBuilder;
- if (localType == null)
- throw new ArgumentNullException("localType");
- if (localType.GetType() != typeof(RuntimeType))
- throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeType"));
- localBuilder = new LocalBuilder(m_localCount, localType, m_methodBuilder);
-
- m_localSignature.AddArgument(localType, pinned);
- m_localCount++;
- return localBuilder;
- }
-
-
-
-
-
-
- public override void Emit(OpCode opcode, MethodInfo meth)
- {
- if (meth == null)
- throw new ArgumentNullException("meth");
-
- int stackchange = 0;
- int tempVal = 0;
- DynamicMethod dynMeth = DynamicMethod.AsDynamicMethod(meth);
- if (dynMeth == null) {
- if (!(meth is RuntimeMethodInfo))
- throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeMethodInfo"), "meth");
-
- if (meth.DeclaringType != null && (meth.DeclaringType.IsGenericType || meth.DeclaringType.IsArray))
- tempVal = m_scope.GetTokenFor(meth.MethodHandle, meth.DeclaringType.TypeHandle);
- else
- tempVal = m_scope.GetTokenFor(meth.MethodHandle);
- }
- else {
-
- if (opcode.Equals(OpCodes.Ldtoken) || opcode.Equals(OpCodes.Ldftn) || opcode.Equals(OpCodes.Ldvirtftn)) {
- throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOpCodeOnDynamicMethod"));
- }
- tempVal = m_scope.GetTokenFor(dynMeth);
- }
-
- EnsureCapacity(7);
- InternalEmit(opcode);
-
- if (opcode.m_push == StackBehaviour.Varpush && meth.ReturnType != typeof(void)) {
- stackchange++;
- }
- if (opcode.m_pop == StackBehaviour.Varpop) {
- stackchange -= meth.GetParametersNoCopy().Length;
- }
-
-
- if (!meth.IsStatic && !(opcode.Equals(OpCodes.Newobj) || opcode.Equals(OpCodes.Ldtoken) || opcode.Equals(OpCodes.Ldftn))) {
- stackchange--;
- }
-
- UpdateStackSize(opcode, stackchange);
-
- m_length = PutInteger4(tempVal, m_length, m_ILStream);
- }
-
- [System.Runtime.InteropServices.ComVisible(true)]
- public override void Emit(OpCode opcode, ConstructorInfo con)
- {
- if (con == null || !(con is RuntimeConstructorInfo))
- throw new ArgumentNullException("con");
- if (con.DeclaringType != null && con.DeclaringType.IsGenericType)
- Emit(opcode, con.MethodHandle, con.DeclaringType.TypeHandle);
- else
- Emit(opcode, con.MethodHandle);
- }
-
- public void Emit(OpCode opcode, RuntimeMethodHandle meth)
- {
- if (meth.IsNullHandle())
- throw new ArgumentNullException("meth");
-
-
-
- int tempVal = m_scope.GetTokenFor(meth);
- EnsureCapacity(7);
- InternalEmit(opcode);
-
-
-
-
-
- UpdateStackSize(opcode, 1);
-
- m_length = PutInteger4(tempVal, m_length, m_ILStream);
- }
-
- public void Emit(OpCode opcode, RuntimeMethodHandle meth, RuntimeTypeHandle typeContext)
- {
- if (meth.IsNullHandle())
- throw new ArgumentNullException("meth");
- if (typeContext.IsNullHandle())
- throw new ArgumentNullException("typeContext");
-
-
-
- int tempVal = m_scope.GetTokenFor(meth, typeContext);
- EnsureCapacity(7);
- InternalEmit(opcode);
-
-
-
-
-
- UpdateStackSize(opcode, 1);
-
- m_length = PutInteger4(tempVal, m_length, m_ILStream);
- }
-
- public override void Emit(OpCode opcode, Type type)
- {
- if (type == null)
- throw new ArgumentNullException("type");
- Emit(opcode, type.TypeHandle);
- }
-
- public void Emit(OpCode opcode, RuntimeTypeHandle typeHandle)
- {
- if (typeHandle.IsNullHandle())
- throw new ArgumentNullException("typeHandle");
-
- int tempVal = m_scope.GetTokenFor(typeHandle);
- EnsureCapacity(7);
- InternalEmit(opcode);
- m_length = PutInteger4(tempVal, m_length, m_ILStream);
- }
-
- public override void Emit(OpCode opcode, FieldInfo field)
- {
- if (field == null)
- throw new ArgumentNullException("field");
- if (!(field is RuntimeFieldInfo))
- throw new ArgumentNullException("field");
- Emit(opcode, field.FieldHandle);
- }
-
- public void Emit(OpCode opcode, RuntimeFieldHandle fieldHandle)
- {
- if (fieldHandle.IsNullHandle())
- throw new ArgumentNullException("fieldHandle");
-
- int tempVal = m_scope.GetTokenFor(fieldHandle);
- EnsureCapacity(7);
- InternalEmit(opcode);
- m_length = PutInteger4(tempVal, m_length, m_ILStream);
- }
-
- public override void Emit(OpCode opcode, string str)
- {
- if (str == null)
- throw new ArgumentNullException("str");
-
- int tempVal = AddStringLiteral(str);
- tempVal = tempVal | 1879048192;
- EnsureCapacity(7);
- InternalEmit(opcode);
- m_length = PutInteger4(tempVal, m_length, m_ILStream);
- }
-
-
-
-
-
-
- public override void EmitCalli(OpCode opcode, CallingConventions callingConvention, Type returnType, Type[] parameterTypes, Type[] optionalParameterTypes)
- {
- int stackchange = 0;
- SignatureHelper sig;
- if (optionalParameterTypes != null)
- if ((callingConvention & CallingConventions.VarArgs) == 0)
-
- throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_NotAVarArgCallingConvention"));
-
- sig = GetMemberRefSignature(callingConvention, returnType, parameterTypes, optionalParameterTypes);
-
- EnsureCapacity(7);
- Emit(OpCodes.Calli);
-
-
- BCLDebug.Assert(opcode.Equals(OpCodes.Calli), "Unexpected opcode passed to EmitCalli.");
-
- if (returnType != typeof(void))
- stackchange++;
-
- if (parameterTypes != null)
- stackchange -= parameterTypes.Length;
-
- if (optionalParameterTypes != null)
- stackchange -= optionalParameterTypes.Length;
-
- if ((callingConvention & CallingConventions.HasThis) == CallingConventions.HasThis)
- stackchange--;
-
- stackchange--;
- UpdateStackSize(opcode, stackchange);
-
- int token = AddSignature(sig.GetSignature(true));
- m_length = PutInteger4(token, m_length, m_ILStream);
- }
-
- public override void EmitCalli(OpCode opcode, CallingConvention unmanagedCallConv, Type returnType, Type[] parameterTypes)
- {
- int stackchange = 0;
- int cParams = 0;
- int i;
- SignatureHelper sig;
-
-
- BCLDebug.Assert(opcode.Equals(OpCodes.Calli), "Unexpected opcode passed to EmitCalli.");
- if (parameterTypes != null)
- cParams = parameterTypes.Length;
-
- sig = SignatureHelper.GetMethodSigHelper(unmanagedCallConv, returnType);
-
- if (parameterTypes != null)
- for (i = 0; i < cParams; i++)
- sig.AddArgument(parameterTypes[i]);
-
-
- if (returnType != typeof(void))
- stackchange++;
-
-
- if (parameterTypes != null)
- stackchange -= cParams;
-
-
- stackchange--;
- UpdateStackSize(opcode, stackchange);
-
- EnsureCapacity(7);
- Emit(OpCodes.Calli);
- int token = AddSignature(sig.GetSignature(true));
- m_length = PutInteger4(token, m_length, m_ILStream);
- }
-
- public override void EmitCall(OpCode opcode, MethodInfo methodInfo, Type[] optionalParameterTypes)
- {
- int tk;
- int stackchange = 0;
-
- if (methodInfo == null)
- throw new ArgumentNullException("methodInfo");
-
- if (methodInfo.ContainsGenericParameters)
- throw new ArgumentException(Environment.GetResourceString("Argument_GenericsInvalid"), "methodInfo");
-
- if (methodInfo.DeclaringType != null && methodInfo.DeclaringType.ContainsGenericParameters)
- throw new ArgumentException(Environment.GetResourceString("Argument_GenericsInvalid"), "methodInfo");
-
- tk = GetMemberRefToken(methodInfo, optionalParameterTypes);
-
- EnsureCapacity(7);
- InternalEmit(opcode);
-
-
- BCLDebug.Assert(opcode.Equals(OpCodes.Call) || opcode.Equals(OpCodes.Callvirt) || opcode.Equals(OpCodes.Newobj), "Unexpected opcode passed to EmitCall.");
-
-
- if (methodInfo.ReturnType != typeof(void))
- stackchange++;
-
- stackchange -= methodInfo.GetParameterTypes().Length;
-
-
- if (!(methodInfo is SymbolMethod) && methodInfo.IsStatic == false && !(opcode.Equals(OpCodes.Newobj)))
- stackchange--;
-
- if (optionalParameterTypes != null)
- stackchange -= optionalParameterTypes.Length;
- UpdateStackSize(opcode, stackchange);
-
- m_length = PutInteger4(tk, m_length, m_ILStream);
- }
-
- public override void Emit(OpCode opcode, SignatureHelper signature)
- {
- int stackchange = 0;
- if (signature == null)
- throw new ArgumentNullException("signature");
-
- EnsureCapacity(7);
- InternalEmit(opcode);
-
-
-
-
-
-
- if (opcode.m_pop == StackBehaviour.Varpop) {
- BCLDebug.Assert(opcode.Equals(OpCodes.Calli), "Unexpected opcode encountered for StackBehaviour VarPop.");
-
- stackchange -= signature.ArgumentCount;
-
- stackchange--;
- UpdateStackSize(opcode, stackchange);
- }
-
- int token = AddSignature(signature.GetSignature(true));
- ;
- m_length = PutInteger4(token, m_length, m_ILStream);
- }
-
-
-
-
-
-
- public override Label BeginExceptionBlock()
- {
- return base.BeginExceptionBlock();
- }
-
- public override void EndExceptionBlock()
- {
- base.EndExceptionBlock();
- }
-
- public override void BeginExceptFilterBlock()
- {
- throw new NotSupportedException(Environment.GetResourceString("InvalidOperation_NotAllowedInDynamicMethod"));
- }
-
- public override void BeginCatchBlock(Type exceptionType)
- {
- if (m_currExcStackCount == 0)
- throw new NotSupportedException(Environment.GetResourceString("Argument_NotInExceptionBlock"));
-
- __ExceptionInfo current = m_currExcStack[m_currExcStackCount - 1];
-
- if (current.GetCurrentState() == __ExceptionInfo.State_Filter) {
- if (exceptionType != null) {
- throw new ArgumentException(Environment.GetResourceString("Argument_ShouldNotSpecifyExceptionType"));
- }
-
- this.Emit(OpCodes.Endfilter);
- }
- else {
-
- if (exceptionType == null) {
- throw new ArgumentNullException("exceptionType");
- }
-
- if (exceptionType.GetType() != typeof(RuntimeType))
- throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeType"));
-
- Label endLabel = current.GetEndLabel();
- this.Emit(OpCodes.Leave, endLabel);
-
-
- UpdateStackSize(OpCodes.Nop, 1);
- }
-
- current.MarkCatchAddr(m_length, exceptionType);
-
-
-
-
- current.m_filterAddr[current.m_currentCatch - 1] = m_scope.GetTokenFor(exceptionType.TypeHandle);
- }
-
- public override void BeginFaultBlock()
- {
- throw new NotSupportedException(Environment.GetResourceString("InvalidOperation_NotAllowedInDynamicMethod"));
- }
-
- public override void BeginFinallyBlock()
- {
- base.BeginFinallyBlock();
- }
-
-
-
-
-
-
- public override void UsingNamespace(string ns)
- {
- throw new NotSupportedException(Environment.GetResourceString("InvalidOperation_NotAllowedInDynamicMethod"));
- }
-
- public override void MarkSequencePoint(ISymbolDocumentWriter document, int startLine, int startColumn, int endLine, int endColumn)
- {
- throw new NotSupportedException(Environment.GetResourceString("InvalidOperation_NotAllowedInDynamicMethod"));
- }
-
- public override void BeginScope()
- {
- throw new NotSupportedException(Environment.GetResourceString("InvalidOperation_NotAllowedInDynamicMethod"));
- }
-
- public override void EndScope()
- {
- throw new NotSupportedException(Environment.GetResourceString("InvalidOperation_NotAllowedInDynamicMethod"));
- }
-
-
-
-
- internal override int GetMaxStackSize()
- {
- return m_maxStackSize;
- }
-
- internal override int GetMemberRefToken(MethodBase methodInfo, Type[] optionalParameterTypes)
- {
- Type[] parameterTypes;
-
- if (optionalParameterTypes != null)
- if ((methodInfo.CallingConvention & CallingConventions.VarArgs) == 0)
-
- throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_NotAVarArgCallingConvention"));
-
- if (!(methodInfo is RuntimeMethodInfo) && DynamicMethod.AsDynamicMethod(methodInfo) == null)
- throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeMethodInfo"), "methodInfo");
-
- ParameterInfo[] paramInfo = methodInfo.GetParametersNoCopy();
- if (paramInfo != null && paramInfo.Length != 0) {
- parameterTypes = new Type[paramInfo.Length];
- for (int i = 0; i < paramInfo.Length; i++) {
- parameterTypes[i] = paramInfo[i].ParameterType;
- }
- }
- else
- parameterTypes = null;
-
- SignatureHelper sig = GetMemberRefSignature(methodInfo.CallingConvention, methodInfo.GetReturnType(), parameterTypes, optionalParameterTypes);
- return m_scope.GetTokenFor(new VarArgMethod(methodInfo as MethodInfo, sig));
- }
-
- internal override SignatureHelper GetMemberRefSignature(CallingConventions call, Type returnType, Type[] parameterTypes, Type[] optionalParameterTypes)
- {
- int cParams;
- int i;
- SignatureHelper sig;
- if (parameterTypes == null)
- cParams = 0;
- else
- cParams = parameterTypes.Length;
- sig = SignatureHelper.GetMethodSigHelper(call, returnType);
- for (i = 0; i < cParams; i++)
- sig.AddArgument(parameterTypes[i]);
- if (optionalParameterTypes != null && optionalParameterTypes.Length != 0) {
-
- sig.AddSentinel();
- for (i = 0; i < optionalParameterTypes.Length; i++)
- sig.AddArgument(optionalParameterTypes[i]);
- }
- return sig;
- }
-
- private int AddStringLiteral(string s)
- {
- int token = m_scope.GetTokenFor(s);
- return token | 1879048192;
- }
-
- private int AddSignature(byte[] sig)
- {
- int token = m_scope.GetTokenFor(sig);
- return token | 285212672;
- }
-
- }
-
- internal class DynamicResolver : Resolver
- {
- #region Private Data Members
- private __ExceptionInfo[] m_exceptions;
- private byte[] m_exceptionHeader;
- private DynamicMethod m_method;
- private byte[] m_code;
- private byte[] m_localSignature;
- private int m_stackSize;
- private DynamicScope m_scope;
- #endregion
-
- #region Internal Methods
- internal DynamicResolver(DynamicILGenerator ilGenerator)
- {
- m_stackSize = ilGenerator.GetMaxStackSize();
- m_exceptions = ilGenerator.GetExceptions();
- m_code = ilGenerator.BakeByteArray();
- m_localSignature = ilGenerator.m_localSignature.InternalGetSignatureArray();
- m_scope = ilGenerator.m_scope;
-
- m_method = (DynamicMethod)ilGenerator.m_methodBuilder;
- m_method.m_resolver = this;
- }
-
- internal DynamicResolver(DynamicILInfo dynamicILInfo)
- {
- m_stackSize = dynamicILInfo.MaxStackSize;
- m_code = dynamicILInfo.Code;
- m_localSignature = dynamicILInfo.LocalSignature;
- m_exceptionHeader = dynamicILInfo.Exceptions;
-
- m_scope = dynamicILInfo.DynamicScope;
-
- m_method = dynamicILInfo.DynamicMethod;
- m_method.m_resolver = this;
- }
-
-
-
- ~DynamicResolver()
- {
- DynamicMethod method = m_method;
-
- if (method == null)
- return;
-
- if (method.m_method.IsNullHandle())
- return;
-
- DestroyScout scout = null;
- try {
- scout = new DestroyScout();
- }
- catch {
-
-
-
- if (!Environment.HasShutdownStarted && !AppDomain.CurrentDomain.IsFinalizingForUnload()) {
-
- GC.ReRegisterForFinalize(this);
- }
- return;
- }
-
-
-
- scout.m_method = method.m_method;
- }
-
- private class DestroyScout
- {
- internal RuntimeMethodHandle m_method;
-
- ~DestroyScout()
- {
- if (m_method.IsNullHandle())
- return;
-
-
- if (m_method.GetResolver() != null) {
- if (!Environment.HasShutdownStarted && !AppDomain.CurrentDomain.IsFinalizingForUnload()) {
-
-
- GC.ReRegisterForFinalize(this);
- }
- return;
- }
-
- m_method.Destroy();
- }
- }
-
-
- internal enum SecurityControlFlags
- {
- SkipVisibilityChecks = 1
- }
-
- internal override void GetJitContext(ref int securityControlFlags, ref RuntimeTypeHandle typeOwner)
- {
- securityControlFlags = (m_method.m_skipVisibility) ? (int)SecurityControlFlags.SkipVisibilityChecks : 0;
- typeOwner = (m_method.m_typeOwner != null) ? m_method.m_typeOwner.TypeHandle : RuntimeTypeHandle.EmptyHandle;
- }
-
- internal override byte[] GetCodeInfo(ref int stackSize, ref int initLocals, ref int EHCount)
- {
- stackSize = m_stackSize;
- if (m_exceptionHeader != null && m_exceptionHeader.Length != 0) {
- if (m_exceptionHeader.Length < 4)
- throw new FormatException();
-
- byte header = m_exceptionHeader[0];
-
-
- if ((header & 64) != 0) {
- byte[] size = new byte[4];
- for (int q = 0; q < 3; q++)
- size[q] = m_exceptionHeader[q + 1];
- EHCount = (BitConverter.ToInt32(size, 0) - 4) / 24;
- }
- else
- EHCount = (m_exceptionHeader[1] - 2) / 12;
- }
- else {
- EHCount = ILGenerator.CalculateNumberOfExceptions(m_exceptions);
- }
- initLocals = (m_method.InitLocals) ? 1 : 0;
- return m_code;
- }
-
- internal override byte[] GetLocalsSignature()
- {
- return m_localSignature;
- }
-
- unsafe internal override byte[] GetRawEHInfo()
- {
- return m_exceptionHeader;
- }
-
- unsafe internal override void GetEHInfo(int excNumber, void* exc)
- {
- CORINFO_EH_CLAUSE* exception = (CORINFO_EH_CLAUSE*)exc;
- for (int i = 0; i < m_exceptions.Length; i++) {
- int excCount = m_exceptions[i].GetNumberOfCatches();
- if (excNumber < excCount) {
-
- exception->Flags = m_exceptions[i].GetExceptionTypes()[excNumber];
- exception->Flags |= Resolver.COR_ILEXCEPTION_CLAUSE_MUST_CACHE_CLASS;
- exception->TryOffset = m_exceptions[i].GetStartAddress();
- if ((exception->Flags & __ExceptionInfo.Finally) != __ExceptionInfo.Finally)
- exception->TryLength = m_exceptions[i].GetEndAddress() - exception->TryOffset;
- else
- exception->TryLength = m_exceptions[i].GetFinallyEndAddress() - exception->TryOffset;
- exception->HandlerOffset = m_exceptions[i].GetCatchAddresses()[excNumber];
- exception->HandlerLength = m_exceptions[i].GetCatchEndAddresses()[excNumber] - exception->HandlerOffset;
-
- exception->ClassTokenOrFilterOffset = m_exceptions[i].GetFilterAddresses()[excNumber];
- break;
- }
- excNumber -= excCount;
- }
- }
-
- internal override string GetStringLiteral(int token)
- {
- return m_scope.GetString(token);
- }
-
- internal override int IsValidToken(int token)
- {
- return (m_scope[token] != null) ? 1 : 0;
- }
-
- unsafe internal override void* GetInstantiationInfo(int token)
- {
- GenericMethodInfo gmi = m_scope[token] as GenericMethodInfo;
- if (gmi != null) {
- return (void*)gmi.m_context.Value;
- }
- return null;
- }
-
- unsafe internal override void* ResolveToken(int token)
- {
- object handle = m_scope[token];
-
- if (handle is RuntimeTypeHandle) {
- RuntimeTypeHandle typeHandle = (RuntimeTypeHandle)handle;
- return (void*)typeHandle.Value;
- }
- else if (handle is RuntimeMethodHandle) {
- RuntimeMethodHandle methodHandle = (RuntimeMethodHandle)handle;
- return (void*)methodHandle.Value;
- }
- else if (handle is RuntimeFieldHandle) {
- RuntimeFieldHandle fieldHandle = (RuntimeFieldHandle)handle;
- return (void*)fieldHandle.Value;
- }
- else if (handle is DynamicMethod) {
- DynamicMethod dynMeth = (DynamicMethod)handle;
- RuntimeMethodHandle methodHandle = dynMeth.GetMethodDescriptor();
- return (void*)methodHandle.Value;
- }
- else if (handle is GenericMethodInfo) {
- &