예제 #1
0
        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);
        }
예제 #2
0
        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()));
        }