private ProjectionMetadataFlags GetFlags(ProjectionMetadata metadata)
        {
            IdAttribute  id   = metadata.Relation.Annotations?.OfType <IdAttribute>().FirstOrDefault();
            OutAttribute out0 = metadata.Relation.Annotations?.OfType <OutAttribute>().FirstOrDefault();
            InAttribute  in0  = metadata.Relation.Annotations?.OfType <InAttribute>().FirstOrDefault();

            IReferenceMetadata      reference = metadata.Identity.GetMetadata <IReferenceMetadata>();
            ProjectionMetadataFlags flags     = ProjectionMetadataFlags.None;

            if (id != null)
            {
                flags |= ProjectionMetadataFlags.Identity;
            }

            if (in0 != null || out0 != null)
            {
                flags |= in0 != null ? ProjectionMetadataFlags.Input : ProjectionMetadataFlags.None;
                flags |= out0 != null ? ProjectionMetadataFlags.Output : ProjectionMetadataFlags.None;
            }
            else if (id != null)
            {
                flags |= ProjectionMetadataFlags.Output;
            }
            else if (reference != null && reference.HasAnyFlag(ReferenceMetadataFlags.Key))
            {
                flags |= ProjectionMetadataFlags.Input | ProjectionMetadataFlags.Output;
            }
            else
            {
                flags |= ProjectionMetadataFlags.Input;
            }

            return(flags);
        }
Ejemplo n.º 2
0
 private static void BuildParameterInfo(MethodInfo methodInfo, ActionWrapper action)
 {
     foreach (var parameterInfo in methodInfo.GetParameters())
     {
         var @in = parameterInfo.GetCustomAttribute <InAttribute>(true);
         if (@in == null)
         {
             var fromBody = parameterInfo.GetCustomAttribute <FromBodyAttribute>(true);
             if (fromBody != null)
             {
                 @in = new InAttribute(InclutionTypes.Body);
             }
             if (@in == null)
             {
                 var fromUri = parameterInfo.GetCustomAttribute <FromUriAttribute>(true);
                 if (fromUri != null)
                 {
                     @in = new InAttribute(InclutionTypes.Path);
                 }
             }
         }
         action.Parameters.Add(new ParameterWrapper {
             Name = parameterInfo.Name, Type = parameterInfo.ParameterType, In = @in?.InclutionType ?? InclutionTypes.Body
         });
     }
 }
Ejemplo n.º 3
0
        public static void TestPseudoCustomAttributes()
        {
            MethodInfo m = typeof(ParametersWithPseudoCustomtAttributes).Project().GetTypeInfo().GetDeclaredMethod("Foo");

            ParameterInfo[] pis = m.GetParameters();
            {
                ParameterInfo       p   = pis[0];
                CustomAttributeData cad = p.CustomAttributes.Single(c => c.AttributeType == typeof(InAttribute).Project());
                InAttribute         i   = cad.UnprojectAndInstantiate <InAttribute>();
            }

            {
                ParameterInfo       p   = pis[1];
                CustomAttributeData cad = p.CustomAttributes.Single(c => c.AttributeType == typeof(OutAttribute).Project());
                OutAttribute        o   = cad.UnprojectAndInstantiate <OutAttribute>();
            }

            {
                ParameterInfo       p   = pis[2];
                CustomAttributeData cad = p.CustomAttributes.Single(c => c.AttributeType == typeof(OptionalAttribute).Project());
                OptionalAttribute   o   = cad.UnprojectAndInstantiate <OptionalAttribute>();
            }

            {
                ParameterInfo       p   = pis[3];
                CustomAttributeData cad = p.CustomAttributes.Single(c => c.AttributeType == typeof(MarshalAsAttribute).Project());
                MarshalAsAttribute  ma  = cad.UnprojectAndInstantiate <MarshalAsAttribute>();
                Assert.Equal(UnmanagedType.I4, ma.Value);
            }
        }
Ejemplo n.º 4
0
		public static IInCord JustInCordFactory(Type[] argTypes, InAttribute attr)
		{
			IInCord ans = null;
			var des = DeserializersFactory.Create(argTypes);
			var gType = argTypes.Length == 1 ? argTypes [0] : typeof(object[]); 
			var gt = typeof(InCord<>).MakeGenericType (gType);
			ans = Activator.CreateInstance (gt, attr.CordId, des) as IInCord;
			return ans;
		}
Ejemplo n.º 5
0
        internal static Attribute[] GetCustomAttributes(RuntimeParameterInfo parameter, RuntimeType caType, out int count)
        {
            count = 0;
            bool flag = caType == (RuntimeType)typeof(object) || caType == (RuntimeType)typeof(Attribute);

            if (!flag && PseudoCustomAttribute.s_pca.GetValueOrDefault(caType) == null)
            {
                return(null);
            }
            Attribute[] array = new Attribute[PseudoCustomAttribute.s_pcasCount];
            if (flag || caType == (RuntimeType)typeof(InAttribute))
            {
                Attribute customAttribute = InAttribute.GetCustomAttribute(parameter);
                if (customAttribute != null)
                {
                    Attribute[] array2 = array;
                    int         num    = count;
                    count       = num + 1;
                    array2[num] = customAttribute;
                }
            }
            if (flag || caType == (RuntimeType)typeof(OutAttribute))
            {
                Attribute customAttribute = OutAttribute.GetCustomAttribute(parameter);
                if (customAttribute != null)
                {
                    Attribute[] array3 = array;
                    int         num    = count;
                    count       = num + 1;
                    array3[num] = customAttribute;
                }
            }
            if (flag || caType == (RuntimeType)typeof(OptionalAttribute))
            {
                Attribute customAttribute = OptionalAttribute.GetCustomAttribute(parameter);
                if (customAttribute != null)
                {
                    Attribute[] array4 = array;
                    int         num    = count;
                    count       = num + 1;
                    array4[num] = customAttribute;
                }
            }
            if (flag || caType == (RuntimeType)typeof(MarshalAsAttribute))
            {
                Attribute customAttribute = MarshalAsAttribute.GetCustomAttribute(parameter);
                if (customAttribute != null)
                {
                    Attribute[] array5 = array;
                    int         num    = count;
                    count       = num + 1;
                    array5[num] = customAttribute;
                }
            }
            return(array);
        }
Ejemplo n.º 6
0
        internal static bool IsDefined(ParameterInfo parameter, Type caType)
        {
            bool flag = (caType == typeof(object)) || (caType == typeof(Attribute));

            if (!flag && (s_pca[caType] == null))
            {
                return(false);
            }
            return(((flag || (caType == typeof(InAttribute))) && InAttribute.IsDefined(parameter)) || (((flag || (caType == typeof(OutAttribute))) && OutAttribute.IsDefined(parameter)) || (((flag || (caType == typeof(OptionalAttribute))) && OptionalAttribute.IsDefined(parameter)) || ((flag || (caType == typeof(MarshalAsAttribute))) && MarshalAsAttribute.IsDefined(parameter)))));
        }
Ejemplo n.º 7
0
        internal static bool IsDefined(RuntimeParameterInfo parameter, RuntimeType caType)
        {
            bool flag = (caType == ((RuntimeType)typeof(object))) || (caType == ((RuntimeType)typeof(Attribute)));

            if (!flag && (s_pca.GetValueOrDefault(caType) == null))
            {
                return(false);
            }
            return(((flag || (caType == ((RuntimeType)typeof(InAttribute)))) && InAttribute.IsDefined(parameter)) || (((flag || (caType == ((RuntimeType)typeof(OutAttribute)))) && OutAttribute.IsDefined(parameter)) || (((flag || (caType == ((RuntimeType)typeof(OptionalAttribute)))) && OptionalAttribute.IsDefined(parameter)) || ((flag || (caType == ((RuntimeType)typeof(MarshalAsAttribute)))) && MarshalAsAttribute.IsDefined(parameter)))));
        }
Ejemplo n.º 8
0
        internal object[] GetPseudoCustomAttributes()
        {
            int count = 0;

            if (IsIn)
            {
                count++;
            }
            if (IsOut)
            {
                count++;
            }
            if (IsOptional)
            {
                count++;
            }
            if (marshalAs != null)
            {
                count++;
            }

            if (count == 0)
            {
                return(null);
            }
            object[] attrs = new object [count];
            count = 0;

            if (IsIn)
            {
                attrs [count++] = new InAttribute();
            }
            if (IsOut)
            {
                attrs [count++] = new OutAttribute();
            }
            if (IsOptional)
            {
                attrs [count++] = new OptionalAttribute();
            }

            if (marshalAs != null)
            {
#if NETCORE
                attrs [count++] = (MarshalAsAttribute)marshalAs.CloneInternal();
#else
                attrs [count++] = marshalAs.Copy();
#endif
            }

            return(attrs);
        }
Ejemplo n.º 9
0
        internal object[] GetPseudoCustomAttributes()
        {
            int count = 0;

            if (IsIn)
            {
                count++;
            }
            if (IsOut)
            {
                count++;
            }
            if (IsOptional)
            {
                count++;
            }
            if (marshalAs != null)
            {
                count++;
            }

            if (count == 0)
            {
                return(null);
            }
            object[] attrs = new object [count];
            count = 0;

            if (IsIn)
            {
                attrs [count++] = new InAttribute();
            }
            if (IsOut)
            {
                attrs [count++] = new OutAttribute();
            }
            if (IsOptional)
            {
                attrs [count++] = new OptionalAttribute();
            }

            if (marshalAs != null)
            {
#if NETCORE
                throw new NotImplementedException();
#else
                attrs [count++] = marshalAs.Copy();
#endif
            }

            return(attrs);
        }
Ejemplo n.º 10
0
        internal object[] GetPseudoCustomAttributes()
        {
            int count = 0;

            if (IsIn)
            {
                count++;
            }
            if (IsOut)
            {
                count++;
            }
            if (IsOptional)
            {
                count++;
            }
#if !MICRO_LIB
            if (marshalAs != null)
            {
                count++;
            }
#endif
            if (count == 0)
            {
                return(null);
            }
            object[] attrs = new object [count];
            count = 0;

            if (IsIn)
            {
                attrs [count++] = new InAttribute();
            }
            if (IsOptional)
            {
                attrs [count++] = new OptionalAttribute();
            }
            if (IsOut)
            {
                attrs [count++] = new OutAttribute();
            }
#if !MICRO_LIB
            if (marshalAs != null)
            {
                attrs [count++] = marshalAs.ToMarshalAsAttribute();
            }
#endif
            return(attrs);
        }
Ejemplo n.º 11
0
        internal static Attribute[] GetCustomAttributes(ParameterInfo parameter, Type caType, out int count)
        {
            count = 0;
            bool flag = (caType == typeof(object)) || (caType == typeof(Attribute));

            if (!flag && (s_pca[caType] == null))
            {
                return(null);
            }
            Attribute[] attributeArray  = new Attribute[s_pcasCount];
            Attribute   customAttribute = null;

            if (flag || (caType == typeof(InAttribute)))
            {
                customAttribute = InAttribute.GetCustomAttribute(parameter);
                if (customAttribute != null)
                {
                    attributeArray[count++] = customAttribute;
                }
            }
            if (flag || (caType == typeof(OutAttribute)))
            {
                customAttribute = OutAttribute.GetCustomAttribute(parameter);
                if (customAttribute != null)
                {
                    attributeArray[count++] = customAttribute;
                }
            }
            if (flag || (caType == typeof(OptionalAttribute)))
            {
                customAttribute = OptionalAttribute.GetCustomAttribute(parameter);
                if (customAttribute != null)
                {
                    attributeArray[count++] = customAttribute;
                }
            }
            if (flag || (caType == typeof(MarshalAsAttribute)))
            {
                customAttribute = MarshalAsAttribute.GetCustomAttribute(parameter);
                if (customAttribute != null)
                {
                    attributeArray[count++] = customAttribute;
                }
            }
            return(attributeArray);
        }
Ejemplo n.º 12
0
        internal object[] GetPseudoCustomAttributes()
        {
            int num = 0;

            if (this.IsIn)
            {
                num++;
            }
            if (this.IsOut)
            {
                num++;
            }
            if (this.IsOptional)
            {
                num++;
            }
            if (this.marshalAs != null)
            {
                num++;
            }
            if (num == 0)
            {
                return(null);
            }
            object[] array = new object[num];
            num = 0;
            if (this.IsIn)
            {
                array[num++] = new InAttribute();
            }
            if (this.IsOptional)
            {
                array[num++] = new OptionalAttribute();
            }
            if (this.IsOut)
            {
                array[num++] = new OutAttribute();
            }
            if (this.marshalAs != null)
            {
                array[num++] = this.marshalAs.ToMarshalAsAttribute();
            }
            return(array);
        }
Ejemplo n.º 13
0
 public bool PosTest1()
 {
     bool retVal = true;
     TestLibrary.TestFramework.BeginScenario("PosTest1: Initialize a instance of InAttribute class");
     try
     {
         InAttribute myInAttribute = new InAttribute();
         if (myInAttribute == null)
         {
             TestLibrary.TestFramework.LogError("001", "Initialize the instance of InAttribute not successfully");
             retVal = false;
         }
     }
     catch (Exception e)
     {
         TestLibrary.TestFramework.LogError("002", "Unexpect exception" + e);
         retVal = false;
     }
     return retVal;
 }
Ejemplo n.º 14
0
    public bool PosTest1()
    {
        bool retVal = true;

        TestLibrary.TestFramework.BeginScenario("PosTest1: Initialize a instance of InAttribute class");
        try
        {
            InAttribute myInAttribute = new InAttribute();
            if (myInAttribute == null)
            {
                TestLibrary.TestFramework.LogError("001", "Initialize the instance of InAttribute not successfully");
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("002", "Unexpect exception" + e);
            retVal = false;
        }
        return(retVal);
    }
Ejemplo n.º 15
0
        internal static Attribute[] GetCustomAttributes(RuntimeParameterInfo parameter, RuntimeType caType, out int count)
        {
            count = 0;
            bool flag = caType == (RuntimeType)typeof(object) || caType == (RuntimeType)typeof(Attribute);

            if (!flag && PseudoCustomAttribute.s_pca.GetValueOrDefault(caType) == (RuntimeType)null)
            {
                return((Attribute[])null);
            }
            Attribute[] attributeArray1 = new Attribute[PseudoCustomAttribute.s_pcasCount];
            if (flag || caType == (RuntimeType)typeof(InAttribute))
            {
                Attribute customAttribute = InAttribute.GetCustomAttribute(parameter);
                if (customAttribute != null)
                {
                    Attribute[] attributeArray2 = attributeArray1;
                    // ISSUE: explicit reference operation
                    // ISSUE: variable of a reference type
                    int& local = @count;
                    // ISSUE: explicit reference operation
                    int num1 = ^ local;
                    int num2 = num1 + 1;
Ejemplo n.º 16
0
        private List <ParameterWrapper> GetMethodParams(MethodInfo implementationMethod)
        {
            var resolver       = _provider.GetService <IServiceParameterResolver>();
            var resolvedParams = resolver?.ResolveParameters(implementationMethod);

            if (resolvedParams != null && resolvedParams.Count() == implementationMethod.GetParameters().Length)
            {
                return(resolvedParams.ToList());
            }
            var methodParams = new List <ParameterWrapper>();

            foreach (var parameterInfo in implementationMethod.GetParameters())
            {
                var @in = parameterInfo.GetCustomAttribute <InAttribute>(true);
                if (@in == null)
                {
                    var fromBody = parameterInfo.GetCustomAttribute <FromBodyAttribute>(true);
                    if (fromBody != null)
                    {
                        @in = new InAttribute(InclutionTypes.Body);
                    }
                    if (@in == null)
                    {
                        var fromUri = parameterInfo.GetCustomAttribute <FromUriAttribute>(true);
                        if (fromUri != null)
                        {
                            @in = new InAttribute(InclutionTypes.Path);
                        }
                    }
                }
                methodParams.Add(new ParameterWrapper {
                    Name = parameterInfo.Name, Type = parameterInfo.ParameterType, In = @in?.InclutionType ?? InclutionTypes.Body
                });
            }
            return(methodParams);
        }
Ejemplo n.º 17
0
		public static IAnsweringCord AnswerCordFactory(Type[] argTypes, Type returnType, InAttribute attr)
		{
			var des = DeserializersFactory.Create(argTypes);
			var ser = SerializersFactory.Create (returnType);
			return  new AnsweringCord(attr.CordId, des, ser);
		}
Ejemplo n.º 18
0
        internal static bool IsDefined(RuntimeParameterInfo parameter, RuntimeType caType)
        {
            bool flag = caType == (RuntimeType)typeof(object) || caType == (RuntimeType)typeof(Attribute);

            return((flag || !(PseudoCustomAttribute.s_pca.GetValueOrDefault(caType) == null)) && (((flag || caType == (RuntimeType)typeof(InAttribute)) && InAttribute.IsDefined(parameter)) || ((flag || caType == (RuntimeType)typeof(OutAttribute)) && OutAttribute.IsDefined(parameter)) || ((flag || caType == (RuntimeType)typeof(OptionalAttribute)) && OptionalAttribute.IsDefined(parameter)) || ((flag || caType == (RuntimeType)typeof(MarshalAsAttribute)) && MarshalAsAttribute.IsDefined(parameter))));
        }
Ejemplo n.º 19
0
        public MethodBuilder BuildAsyncVoidMethod(TypeBuilder type, MethodInfo implementationMethod)
        {
            // Declaring method builder
            // Method attributes
            const MethodAttributes methodAttributes = MethodAttributes.Public
                                                      | MethodAttributes.Virtual
                                                      | MethodAttributes.Final
                                                      | MethodAttributes.HideBySig
                                                      | MethodAttributes.NewSlot;
            var method = type.DefineMethod(implementationMethod.Name, methodAttributes);

            // Preparing Reflection instances
            #region MyRegion
            ConstructorInfo route = typeof(RouteAttribute).GetConstructor(
                BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic,
                null,
                new Type[] {
                typeof(String)
            },
                null
                );
            ConstructorInfo httpGet   = httpMethodAttribute(implementationMethod);
            ConstructorInfo uriAttrib = typeof(FromUriAttribute).GetConstructor(
                BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic,
                null,
                new Type[] {
            },
                null
                );
            ConstructorInfo bodyAttrib = typeof(FromBodyAttribute).GetConstructor(
                BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic,
                null,
                new Type[] {
            },
                null
                );
            MethodInfo gatherParams = typeof(ServiceWrapperBase <>).MakeGenericType(implementationMethod.DeclaringType).GetMethod(
                "GatherParameters",
                BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic,
                null,
                new Type[] {
                typeof(string),
                typeof(object[])
            },
                null
                );
            var        baseType       = typeof(ServiceWrapperBase <>).MakeGenericType(implementationMethod.DeclaringType);
            var        implementation = baseType.GetRuntimeFields().Single(f => f.Name == "implementation");
            MethodInfo getValue       = typeof(ParameterWrapper).GetMethod(
                "get_value",
                BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic,
                null,
                new Type[] {
            },
                null
                );
            MethodInfo createResponse = baseType.GetMethod("CreateResponseVoidAsync", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
            MethodInfo method9        = baseType.GetMethod(
                "CreateErrorResponse",
                BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic,
                null,
                new Type[] {
                typeof(Exception)
            },
                null
                );
            MethodInfo fromResult = typeof(Task).GetMethod("FromResult").MakeGenericMethod(typeof(HttpResponseMessage));

            #endregion

            // Setting return type
            method.SetReturnType(typeof(Task <HttpResponseMessage>));
            // Adding parameters
            var methodParams = new List <ParameterWrapper>();
            foreach (var parameterInfo in implementationMethod.GetParameters())
            {
                var @in = parameterInfo.GetCustomAttribute <InAttribute>(true);
                if (@in == null)
                {
                    var fromBody = parameterInfo.GetCustomAttribute <FromBodyAttribute>(true);
                    if (fromBody != null)
                    {
                        @in = new InAttribute(InclutionTypes.Body);
                    }
                    if (@in == null)
                    {
                        var fromUri = parameterInfo.GetCustomAttribute <FromUriAttribute>(true);
                        if (fromUri != null)
                        {
                            @in = new InAttribute(InclutionTypes.Path);
                        }
                    }
                }
                if (@in.InclutionType != InclutionTypes.Header)
                {
                    methodParams.Add(new ParameterWrapper {
                        Name = parameterInfo.Name, Type = parameterInfo.ParameterType, In = @in?.InclutionType ?? InclutionTypes.Body
                    });
                }
            }
            var pTypes = methodParams.Select(p => p.Type).ToArray();
            method.SetParameters(pTypes.ToArray());
            // Parameter id
            int pid = 1;
            foreach (var parameterWrapper in methodParams)
            {
                try
                {
                    var p = method.DefineParameter(pid, ParameterAttributes.None, parameterWrapper.Name);
                    if (parameterWrapper.In == InclutionTypes.Path)
                    {
                        p.SetCustomAttribute(new CustomAttributeBuilder(uriAttrib, new Type[] { }));
                    }
                    else if (parameterWrapper.In == InclutionTypes.Body)
                    {
                        p.SetCustomAttribute(new CustomAttributeBuilder(bodyAttrib, new Type[] { }));
                    }
                    pid++;
                }
                catch (Exception)
                {
                    throw;
                }
            }
            // Adding custom attributes to method
            // [RouteAttribute]
            method.SetCustomAttribute(
                new CustomAttributeBuilder(
                    route,
                    new[] {
                implementationMethod.GetCustomAttribute <RouteAttribute>().Template
            }
                    )
                );
            method.SetCustomAttribute(
                new CustomAttributeBuilder(
                    httpGet,
                    new Type[] { }
                    )
                );
            ILGenerator gen = method.GetILGenerator();
            // Preparing locals
            LocalBuilder parameters        = gen.DeclareLocal(typeof(Object[]));
            LocalBuilder serviceParameters = gen.DeclareLocal(typeof(ParameterWrapper[]));
            LocalBuilder result            = gen.DeclareLocal(typeof(Task));
            LocalBuilder message           = gen.DeclareLocal(typeof(Task <HttpResponseMessage>));
            LocalBuilder ex = gen.DeclareLocal(typeof(Exception));
            // Preparing labels
            // Writing body
            gen.Emit(OpCodes.Nop);
            gen.BeginExceptionBlock();
            gen.Emit(OpCodes.Nop);
            var ps = pTypes;
            EmitHelpers.EmitInt32(gen, ps.Length);
            gen.Emit(OpCodes.Newarr, typeof(object));
            for (int j = 0; j < ps.Length; j++)
            {
                gen.Emit(OpCodes.Dup);
                EmitHelpers.EmitInt32(gen, j);
                EmitHelpers.EmitLdarg(gen, j + 1);
                var paramType = ps[j];
                if (paramType.IsValueType)
                {
                    gen.Emit(OpCodes.Box, paramType);
                }
                gen.Emit(OpCodes.Stelem_Ref);
            }
            gen.Emit(OpCodes.Stloc_0);
            gen.Emit(OpCodes.Ldarg_0);
            gen.Emit(OpCodes.Ldstr, implementationMethod.Name);
            gen.Emit(OpCodes.Ldloc_0);
            gen.Emit(OpCodes.Call, gatherParams);
            gen.Emit(OpCodes.Stloc_1);
            gen.Emit(OpCodes.Ldarg_0);
            gen.Emit(OpCodes.Ldfld, implementation);
            int iii = 0;
            foreach (var parameterWrapper in methodParams)
            {
                gen.Emit(OpCodes.Ldloc_1);
                EmitHelpers.EmitInt32(gen, iii);
                gen.Emit(OpCodes.Ldelem_Ref);
                gen.Emit(OpCodes.Callvirt, getValue);
                if (parameterWrapper.Type.IsValueType)
                {
                    gen.Emit(OpCodes.Unbox_Any, parameterWrapper.Type);
                }
                else
                {
                    gen.Emit(OpCodes.Castclass, parameterWrapper.Type);
                }
                iii++;
            }
            gen.Emit(OpCodes.Callvirt, implementationMethod);
            gen.Emit(OpCodes.Stloc_2);
            gen.Emit(OpCodes.Ldarg_0);
            gen.Emit(OpCodes.Ldc_I4, 200);
            gen.Emit(OpCodes.Ldloc_2);
            gen.Emit(OpCodes.Call, createResponse);
            gen.Emit(OpCodes.Stloc_3);
            gen.BeginCatchBlock(typeof(Exception));
            gen.Emit(OpCodes.Stloc_S, 4);
            gen.Emit(OpCodes.Nop);
            gen.Emit(OpCodes.Ldarg_0);
            gen.Emit(OpCodes.Ldloc_S, 4);
            gen.Emit(OpCodes.Call, method9);
            gen.Emit(OpCodes.Call, fromResult);
            gen.Emit(OpCodes.Stloc_3);
            gen.EndExceptionBlock();
            gen.Emit(OpCodes.Ldloc_3);
            gen.Emit(OpCodes.Ret);
            // finished
            return(method);
        }