public OperandReaderContext_DynamicMethod(DynamicMethod method) { this.name = method.Name; ILGenerator ILGen = method.GetILGenerator(); this.maxStackSize = RTTypes.GetMaxStackSize(ILGen); this.@this = method.DeclaringType; this.initLocals = method.InitLocals; this.arguments = method.GetParameters(); InitVariables(ILGen); InitMethodSpec(method); // this.resolver = RTTypes.GetResolver(method); if (resolver != null) { this.ILBytes = RTTypes.GetIL(resolver); this.resolveToken = RTTypes.GetTokenResolver(resolver); this.resolveString = RTTypes.GetStringResolver(resolver); this.resolveSignature = RTTypes.GetSignatureResolver(resolver); this.typeFromHandle = RTTypes.GetTypeFromHandleUnsafe(); this.methodFromHandles = RTTypes.GetMethodFromHandles(); this.fieldFromHandles = RTTypes.GetFieldFromHandles(); } else { this.ILBytes = new byte[ILGen.ILOffset]; RTTypes.CopyILStream(ILGen, ILBytes); // TODO } }
public OperandReaderContext(MethodBase method, MethodBody methodBody) { RTTypes.TryPrepareMethod(method); this.module = method.Module; this.name = method.Name; // var implFlags = method.GetMethodImplementationFlags(); this.initLocals = (methodBody != null) && methodBody.InitLocals; this.maxStackSize = (methodBody != null) ? methodBody.MaxStackSize : 0; this.@this = method.DeclaringType; this.variables = (methodBody != null) ? methodBody.LocalVariables.ToArray() : new object[] { }; this.arguments = method.GetParameters(); ConstructorInfo cInfo = method as ConstructorInfo; if (cInfo != null) { this.methodSpec = (cInfo.IsStatic ? "static " : string.Empty) + ".ctor " + cInfo.DeclaringType.ToString() + " " + implFlags.ToString().ToLower(); } MethodInfo mInfo = method as MethodInfo; if (mInfo != null) { this.methodSpec = (mInfo.IsStatic ? "static " : "instance ") + ((mInfo.ReturnType != null && mInfo.ReturnType != typeof(void)) ? mInfo.ReturnType.ToString() + " " : "void ") + mInfo.Name + " " + implFlags.ToString().ToLower(); } methodArguments = method.IsGenericMethod ? method.GetGenericArguments() : null; typeArguments = (method.DeclaringType != null) && method.DeclaringType.IsGenericType ? method.DeclaringType.GetGenericArguments() : null; // this.ILBytes = (methodBody != null) ? methodBody.GetILAsByteArray() : null; }
void InitVariables(ILGenerator ILGen) { var localSig = RTTypes.GetLocalSignature(ILGen); this.variables = new Readers.LocalSignatureReader(localSig).Locals; }