public override void GenerateConversion(IProxyModuleCoderAccess proxyModule, ILGenerator gen)
 {
     var target = gen.DeclareLocal(_fromType);
     gen.Emit(OpCodes.Stloc, target); // store the value to be converted
     var pmField = proxyModule.GetProxyModuleField();
     gen.Emit(OpCodes.Ldsfld, pmField); // push static ProxyModule instance for this ProxyModule
     gen.Emit(OpCodes.Call, FromProxyModuleMethod); // DuckFactory.FromProxyModule([s0])
     gen.Emit(OpCodes.Ldloc, target);
     var genMakeDuckProxyForMethod = MakeDuckProxyForMethod.MakeGenericMethod(_subjectType);
     gen.Emit(OpCodes.Callvirt, genMakeDuckProxyForMethod); // [s1].MakeDuckProxyFor<_fromType>([s0])
 }
Beispiel #2
0
        public override void GenerateConversion(IProxyModuleCoderAccess proxyModule, ILGenerator gen)
        {
            var target = gen.DeclareLocal(_fromType);

            gen.Emit(OpCodes.Stloc, target); // store the value to be converted
            var pmField = proxyModule.GetProxyModuleField();

            gen.Emit(OpCodes.Ldsfld, pmField);             // push static ProxyModule instance for this ProxyModule
            gen.Emit(OpCodes.Call, FromProxyModuleMethod); // DuckFactory.FromProxyModule([s0])
            gen.Emit(OpCodes.Ldloc, target);
            var genMakeDuckProxyForMethod = MakeDuckProxyForMethod.MakeGenericMethod(_subjectType);

            gen.Emit(OpCodes.Callvirt, genMakeDuckProxyForMethod); // [s1].MakeDuckProxyFor<_fromType>([s0])
        }
Beispiel #3
0
        static FieldInfo GenerateStaticType(Type realSubjectType, Type subjectType, IProxyModuleCoderAccess proxyModule)
        {
            var    mb        = proxyModule.ModuleBuilder;
            var    fieldType = typeof(ISubjectMethodExists <>).MakeGenericType(subjectType);
            string typeName  = proxyModule.AssemblyName + ".SmeHolder_" + Guid.NewGuid().ToString("N");
            var    tb        = mb.DefineType(typeName, TypeAttributes.Class | TypeAttributes.Abstract | TypeAttributes.Sealed);
            var    field     = tb.DefineField("_i", fieldType, FieldAttributes.Static | FieldAttributes.Assembly);

            var staticCons = tb.DefineConstructor(MethodAttributes.Static, CallingConventions.Standard, null);
            var gen        = staticCons.GetILGenerator();

            var factoryMethod = typeof(DuckProxySubjectMethodExistsCoder).GetMethod("SubjectMethodExistsFactory")
                                .MakeGenericMethod(subjectType);

            gen.Emit(OpCodes.Ldsfld, proxyModule.GetProxyModuleField());
            gen.EmitLdType(realSubjectType);
            gen.EmitCall(OpCodes.Call, factoryMethod, null);
            gen.Emit(OpCodes.Stsfld, field);
            gen.Emit(OpCodes.Ret);
            tb.CreateType();
            return(field);
        }