private void EmitILForConstructor(ILGenerator ilGenerator, Instruction instruction, MemberInfo memberInfo) { ConstructorInfo constructorInfo = memberInfo as ConstructorInfo; if (PoseContext.StubCache.TryGetValue(constructorInfo, out DynamicMethod stub)) { ilGenerator.Emit(OpCodes.Ldtoken, constructorInfo); ilGenerator.Emit(OpCodes.Ldtoken, constructorInfo.DeclaringType); ilGenerator.Emit(OpCodes.Call, stub); return; } MethodBody methodBody = constructorInfo.GetMethodBody(); if (methodBody == null) { ilGenerator.Emit(instruction.OpCode, constructorInfo); return; } if (instruction.OpCode != OpCodes.Newobj && instruction.OpCode != OpCodes.Call) { ilGenerator.Emit(instruction.OpCode, constructorInfo); return; } stub = Stubs.GenerateStubForConstructor(constructorInfo, instruction.OpCode, constructorInfo.IsForValueType()); ilGenerator.Emit(OpCodes.Ldtoken, constructorInfo); ilGenerator.Emit(OpCodes.Ldtoken, constructorInfo.DeclaringType); ilGenerator.Emit(OpCodes.Call, stub); PoseContext.StubCache.TryAdd(constructorInfo, stub); }
private void EmitILForConstructor(ILGenerator ilGenerator, Instruction instruction, MemberInfo memberInfo) { ConstructorInfo constructorInfo = memberInfo as ConstructorInfo; MethodBody methodBody = constructorInfo.GetMethodBody(); if (methodBody == null) { ilGenerator.Emit(instruction.OpCode, constructorInfo); return; } if (instruction.OpCode != OpCodes.Newobj && instruction.OpCode != OpCodes.Call) { ilGenerator.Emit(instruction.OpCode, constructorInfo); return; } ilGenerator.Emit(OpCodes.Ldtoken, constructorInfo); ilGenerator.Emit(OpCodes.Ldtoken, constructorInfo.DeclaringType); ilGenerator.Emit(OpCodes.Call, Stubs.GenerateStubForConstructor(constructorInfo, instruction.OpCode, constructorInfo.IsForValueType())); }