예제 #1
0
        internal static bool Emit(DynamicTypeWrapper.FinishContext context, ClassFile classFile, int constantPoolIndex, ClassFile.ConstantPoolItemInvokeDynamic cpi, CodeEmitter ilgen)
        {
#if !WINRT
            ClassFile.BootstrapMethod bsm = classFile.GetBootstrapMethod(cpi.BootstrapMethod);
            if (!IsLambdaMetafactory(classFile, bsm) && !IsLambdaAltMetafactory(classFile, bsm))
            {
                return(false);
            }
            LambdaMetafactory lmf = context.GetValue <LambdaMetafactory>(constantPoolIndex);
            if (lmf.ctor == null && !lmf.EmitImpl(context, classFile, cpi, bsm, ilgen))
            {
#if STATIC_COMPILER
                if (context.TypeWrapper.GetClassLoader().DisableDynamicBinding)
                {
                    StaticCompiler.IssueMessage(Message.UnableToCreateLambdaFactory);
                }
#endif
                return(false);
            }
            ilgen.Emit(OpCodes.Newobj, lmf.ctor);
            // the CLR verification rules about type merging mean we have to explicitly cast to the interface type here
            ilgen.Emit(OpCodes.Castclass, cpi.GetRetType().TypeAsBaseType);
            return(true);
#else
            throw new NotImplementedException();
#endif
        }