当前位置: 首页>>代码示例>>C#>>正文


C# MethodBuilder.SetReturnType方法代码示例

本文整理汇总了C#中System.Reflection.Emit.MethodBuilder.SetReturnType方法的典型用法代码示例。如果您正苦于以下问题:C# MethodBuilder.SetReturnType方法的具体用法?C# MethodBuilder.SetReturnType怎么用?C# MethodBuilder.SetReturnType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Reflection.Emit.MethodBuilder的用法示例。


在下文中一共展示了MethodBuilder.SetReturnType方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CopyMethodSignature

        /// <summary>
        /// Copies the method signature from one method to another.
        /// This includes generic parameters, constraints and parameters.
        /// </summary>
        /// <param name="sourceMethod">The source method.</param>
        /// <param name="targetMethod">The target method.</param>
        internal static void CopyMethodSignature(MethodInfo sourceMethod, MethodBuilder targetMethod)
        {
            CopyGenericSignature(sourceMethod, targetMethod);

            targetMethod.SetReturnType(sourceMethod.ReturnType);

            // copy the parameters and attributes
            // it seems that we can use the source parameters directly because the target method is derived
            // from the source method
            var parameters = sourceMethod.GetParameters();
            targetMethod.SetParameters(parameters.Select(p => p.ParameterType).ToArray());

            for (int i = 0; i < parameters.Length; i++)
            {
                var parameter = parameters[i];
                targetMethod.DefineParameter(i + 1, parameter.Attributes, parameter.Name);
            }
        }
开发者ID:jamezor,项目名称:EventSourceProxy,代码行数:24,代码来源:ProxyHelper.cs

示例2: MethodBuilderHelper

		/// <summary>
		/// Initializes a new instance of the <see cref="MethodBuilderHelper"/> class
		/// with the specified parameters.
		/// </summary>
		/// <param name="typeBuilder">Associated <see cref="TypeBuilderHelper"/>.</param>
		/// <param name="methodBuilder">A <see cref="MethodBuilder"/></param>
		/// <param name="genericArguments">Generic arguments of the method.</param>
		/// <param name="returnType">The return type of the method.</param>
		/// <param name="parameterTypes">The types of the parameters of the method.</param>
		internal MethodBuilderHelper(
			TypeBuilderHelper  typeBuilder,
			MethodBuilder      methodBuilder,
			Type[]             genericArguments,
			Type               returnType,
			Type[]             parameterTypes
			)
			: base(typeBuilder)
		{
			if (methodBuilder    == null) throw new ArgumentNullException("methodBuilder");
			if (genericArguments == null) throw new ArgumentNullException("genericArguments");

			_methodBuilder = methodBuilder;

			var genArgNames = genericArguments.Select(t => t.Name).ToArray();
			var genParams   = methodBuilder.DefineGenericParameters(genArgNames);

			// Copy parameter constraints.
			//
			List<Type> interfaceConstraints = null;

			for (var i = 0; i < genParams.Length; i++)
			{
				genParams[i].SetGenericParameterAttributes(genericArguments[i].GenericParameterAttributes);

				foreach (var constraint in genericArguments[i].GetGenericParameterConstraints())
				{
					if (constraint.IsClass)
						genParams[i].SetBaseTypeConstraint(constraint);
					else
					{
						if (interfaceConstraints == null)
							interfaceConstraints = new List<Type>();
						interfaceConstraints.Add(constraint);
					}
				}

				if (interfaceConstraints != null && interfaceConstraints.Count != 0)
				{
					genParams[i].SetInterfaceConstraints(interfaceConstraints.ToArray());
					interfaceConstraints.Clear();
				}
			}

			// When a method contains a generic parameter we need to replace all
			// generic types from methodInfoDeclaration with local ones.
			//
			for (var i = 0; i < parameterTypes.Length; i++)
				parameterTypes[i] = TypeHelper.TranslateGenericParameters(parameterTypes[i], genParams);

			methodBuilder.SetParameters(parameterTypes);
			methodBuilder.SetReturnType(TypeHelper.TranslateGenericParameters(returnType, genParams));

			// Once all generic stuff is done is it is safe to call SetCustomAttribute
			//
			methodBuilder.SetCustomAttribute(Type.Assembly.BLToolkitAttribute);
		}
开发者ID:MajidSafari,项目名称:bltoolkit,代码行数:66,代码来源:MethodBuilderHelper.cs

示例3: InitializeReturnType

        private void InitializeReturnType(MethodBuilder methodBuilder, MethodReturnType returnType)
        {
            methodBuilder.SetReturnType(ResolveReturnType(returnType));

            ParameterBuilder parameterBuilder = methodBuilder.DefineParameter(0,
                System.Reflection.ParameterAttributes.Retval, null);

            if (returnType.HasConstant)
                parameterBuilder.SetConstant(returnType.Constant);

            metadataPass.Add(delegate
            {
                InitializeCustomAttributes(parameterBuilder.SetCustomAttribute, returnType.CustomAttributes);
            });
        }
开发者ID:dougrathbone,项目名称:mbunit-v3,代码行数:15,代码来源:DynamicAssemblyBuilder.cs

示例4: CompileOut

        private void CompileOut()
        {
            Out = utilityClass.DefineMethod(Constants.OutMethodName, MethodAttributes.Public | MethodAttributes.Static);

            var genericParameters = declaration.TypeParameters.Any() ? Out.DefineGenericParameters(declaration.TypeParameters) : TypeBuilder.EmptyTypes;

            var returnType = declaration.TypeParameters.Any()
                ? TypeBuilder.MakeGenericType(genericParameters)
                : TypeBuilder;

            var fGreatestFixedPoint = FunctorTypeMapper.Map(declaration.Type, declaration.VariableName, returnType, genericParameters, runtimeContainer);

            Out.SetParameters(fGreatestFixedPoint);

            Out.SetReturnType(returnType);

            Out.SetCustomAttribute(new CustomAttributeBuilder(typeof(ExtensionAttribute).GetConstructors()[0], new object[0]));

            var outBody = Out.GetILGenerator();
            outBody.Emit(OpCodes.Ldarg_0);
            outBody.Emit(OpCodes.Newobj, declaration.TypeParameters.Any()
                ? TypeBuilder.GetConstructor(
                   InFunction.MakeGenericType(genericParameters),
                   InFunctionConstructor)
                : InFunctionConstructor);
            outBody.Emit(OpCodes.Call, fmap.MakeGenericMethod(new[] { returnType, fGreatestFixedPoint }.Concat(genericParameters).ToArray()));
            outBody.Emit(OpCodes.Call, Ana.MakeGenericMethod(new[] { fGreatestFixedPoint }.Concat(genericParameters).ToArray()));
            outBody.Emit(OpCodes.Ret);
        }
开发者ID:paf31,项目名称:Purity,代码行数:29,代码来源:GFixCompiler.cs

示例5: Compile

        public void Compile()
        {
            GreatestFixedPointFunction = module.DefineType(moduleName + '.' + Constants.TypesNamespace + '.' + name + Constants.FunctionSuffix,
                 TypeAttributes.Public | TypeAttributes.Interface | TypeAttributes.Abstract);

            var functionClassGenericParameters = GreatestFixedPointFunction.DefineGenericParameters(new[] { Constants.GFixFunctionClassGenericParameterName }.Concat(declaration.TypeParameters).ToArray());

            GreatestFixedPointFunctionApplyMethod = GreatestFixedPointFunction.DefineMethod(Constants.ApplyMethodName,
                 MethodAttributes.Public | MethodAttributes.Abstract | MethodAttributes.Virtual);

            var underlyingType = GreatestFixedPointFunctionApplyMethod.DefineGenericParameters(Constants.ApplyMethodGenericParameterName)[0];

            var functorClass = FunctorTypeMapper.Map(declaration.Type, declaration.VariableName, underlyingType,
                functionClassGenericParameters.Skip(1).ToArray(), runtimeContainer);

            GreatestFixedPointFunctionApplyMethod.SetParameters(underlyingType, typeof(IFunction<,>).MakeGenericType(underlyingType, functorClass));
            GreatestFixedPointFunctionApplyMethod.SetReturnType(functionClassGenericParameters[0]);

            TypeBuilder = module.DefineType(moduleName + '.' + Constants.TypesNamespace + '.' + name,
                 TypeAttributes.Public | TypeAttributes.Interface | TypeAttributes.Abstract);

            var typeGenericParameters = declaration.TypeParameters.Any() ? TypeBuilder.DefineGenericParameters(declaration.TypeParameters) : TypeBuilder.EmptyTypes;

            GreatestFixedPointApplyMethod = TypeBuilder.DefineMethod(Constants.ApplyMethodName,
                 MethodAttributes.Public | MethodAttributes.Abstract | MethodAttributes.Virtual);

            var resultTypeGfix = GreatestFixedPointApplyMethod.DefineGenericParameters(Constants.GFixFunctionClassGenericParameterName)[0];

            GreatestFixedPointApplyMethod.SetParameters(GreatestFixedPointFunction.MakeGenericType(new[] { resultTypeGfix }.Concat(typeGenericParameters).ToArray()));
            GreatestFixedPointApplyMethod.SetReturnType(resultTypeGfix);

            CompileAnaClass();

            CompileAna();

            CompileAnaFunction();

            CompileAnaFunction1();

            CompileIn();

            CompileInFunction();

            CompileOut();

            CompileOutFunction();

            TypeBuilder.SetCustomAttribute(new CustomAttributeBuilder(
                typeof(InfiniteAttribute).GetConstructors()[0],
                new object[]
                {
                    declaration.ConstructorFunctionName,
                    declaration.DestructorFunctionName,
                    declaration.AnaFunctionName,
                    InFunction
                }));
        }
开发者ID:paf31,项目名称:Purity,代码行数:57,代码来源:GFixCompiler.cs

示例6: CompileAna

        private void CompileAna()
        {
            Ana = utilityClass.DefineMethod(Constants.AnaMethodName, MethodAttributes.Public | MethodAttributes.Static);

            var anaGenericParameters = Ana.DefineGenericParameters(new[] { Constants.AnaMethodGenericParameterName }.Concat(declaration.TypeParameters).ToArray());

            Ana.SetReturnType(declaration.TypeParameters.Any()
                 ? TypeBuilder.MakeGenericType(anaGenericParameters.Skip(1).ToArray())
                 : TypeBuilder);

            var functorClass = FunctorTypeMapper.Map(declaration.Type, declaration.VariableName, anaGenericParameters[0], anaGenericParameters.Skip(1).ToArray(), runtimeContainer);

            var generatorType = typeof(IFunction<,>).MakeGenericType(anaGenericParameters[0], functorClass);

            Ana.SetParameters(anaGenericParameters[0], generatorType);

            var anaBody = Ana.GetILGenerator();
            anaBody.Emit(OpCodes.Ldarg_0);
            anaBody.Emit(OpCodes.Ldarg_1);
            anaBody.Emit(OpCodes.Newobj, TypeBuilder.GetConstructor(AnaClass.MakeGenericType(anaGenericParameters), AnaClassConstructor));
            anaBody.Emit(OpCodes.Ret);
        }
开发者ID:paf31,项目名称:Purity,代码行数:22,代码来源:GFixCompiler.cs

示例7: CompileIn

        private void CompileIn()
        {
            CompileInGeneratingFunction();

            In = utilityClass.DefineMethod(Constants.InMethodName, MethodAttributes.Public | MethodAttributes.Static);

            var genericParameters = declaration.TypeParameters.Any() ? In.DefineGenericParameters(declaration.TypeParameters) : TypeBuilder.EmptyTypes;

            var resultType = declaration.TypeParameters.Any()
                ? TypeBuilder.MakeGenericType(genericParameters.ToArray())
                : TypeBuilder;

            In.SetReturnType(FunctorTypeMapper.Map(declaration.Type, declaration.VariableName, resultType, genericParameters, runtimeContainer));

            In.SetParameters(resultType);

            In.SetCustomAttribute(new CustomAttributeBuilder(typeof(ExtensionAttribute).GetConstructors()[0], new object[0]));

            var fGreatestFixedPoint = FunctorTypeMapper.Map(declaration.Type, declaration.VariableName, resultType, genericParameters, runtimeContainer);

            var applyMethodGenericClass = declaration.TypeParameters.Any()
                ? TypeBuilder.GetMethod(
                   TypeBuilder.MakeGenericType(genericParameters),
                   GreatestFixedPointApplyMethod)
                : GreatestFixedPointApplyMethod;
            var applyMethodGenericMethod = applyMethodGenericClass.MakeGenericMethod(fGreatestFixedPoint);

            var inBody = In.GetILGenerator();
            inBody.Emit(OpCodes.Ldarg_0);
            inBody.Emit(OpCodes.Newobj, declaration.TypeParameters.Any()
                ? TypeBuilder.GetConstructor(
                   InClass.MakeGenericType(genericParameters),
                   InGeneratingFunctionConstructor)
                : InGeneratingFunctionConstructor);
            inBody.Emit(OpCodes.Callvirt, applyMethodGenericMethod);
            inBody.Emit(OpCodes.Ret);
        }
开发者ID:paf31,项目名称:Purity,代码行数:37,代码来源:GFixCompiler.cs

示例8: AdjustParameterTypes

        private static void AdjustParameterTypes(ParameterInfo[] parameters,
                                                 Func<Type, Type> typeReplacer,
                                                 MethodDefinition method)
        {
            var fixedParams = new Type[parameters.Length];
            foreach (var parameter in parameters)
            {
                var paramType = typeReplacer(parameter.ParameterType);
                fixedParams[parameter.Position] = paramType;
                method.DefineParameter(parameter.Position, parameter.Attributes, parameter.Name);
            }
            // Set fixed parameters having correct generic parameters.
            method.SetParameters(fixedParams);

            // Set fixed return type with correct generic parameter.
            method.SetReturnType(typeReplacer(method.ReturnType));
        }
开发者ID:Pomona,项目名称:Pomona,代码行数:17,代码来源:ProxyBuilder.cs

示例9: Compile

        public void Compile()
        {
            TypeBuilder = module.DefineType(moduleName + '.' + Constants.TypesNamespace + '.' + name,
                TypeAttributes.Public | TypeAttributes.Interface | TypeAttributes.Abstract);

            var genericParameters = declaration.TypeParameters.Any() ? ((TypeBuilder)TypeBuilder).DefineGenericParameters(declaration.TypeParameters) : TypeBuilder.EmptyTypes;

            Cata = ((TypeBuilder)TypeBuilder).DefineMethod(Constants.CataMethodName,
                MethodAttributes.Public | MethodAttributes.Abstract | MethodAttributes.Virtual);

            var cataReturnType = Cata.DefineGenericParameters(Constants.CataMethodGenericParameterName)[0];

            var functorClass = FunctorTypeMapper.Map(declaration.Type, declaration.VariableName, cataReturnType, genericParameters, runtimeContainer);

            Cata.SetParameters(typeof(IFunction<,>).MakeGenericType(functorClass, cataReturnType));
            Cata.SetReturnType(cataReturnType);

            CompileCataFunction();

            CompileCataFunction1();

            CompileOutClass();

            CompileOut();

            CompileOutFunction();

            CompileIn();

            CompileInFunction();

            TypeBuilder.SetCustomAttribute(new CustomAttributeBuilder(typeof(FiniteAttribute).GetConstructors()[0],
                new object[]
                {
                    declaration.ConstructorFunctionName,
                    declaration.DestructorFunctionName,
                    declaration.CataFunctionName,
                    InFunction
                }));
        }
开发者ID:paf31,项目名称:Purity,代码行数:40,代码来源:LFixCompiler.cs

示例10: CompileIn

        private void CompileIn()
        {
            In = utilityClass.DefineMethod(Constants.InMethodName, MethodAttributes.Public | MethodAttributes.Static);

            var genericParameters = declaration.TypeParameters.Any() ? In.DefineGenericParameters(declaration.TypeParameters) : TypeBuilder.EmptyTypes;

            var inputParameter = declaration.TypeParameters.Any() ? TypeBuilder.MakeGenericType(genericParameters.ToArray()) : TypeBuilder;

            In.SetReturnType(FunctorTypeMapper.Map(declaration.Type, declaration.VariableName, inputParameter, genericParameters, runtimeContainer));

            In.SetParameters(inputParameter);

            In.SetCustomAttribute(new CustomAttributeBuilder(typeof(ExtensionAttribute).GetConstructors()[0], new object[0]));

            var inBody = In.GetILGenerator();

            var fLeastFixedPoint = FunctorTypeMapper.Map(declaration.Type, declaration.VariableName, inputParameter, genericParameters, runtimeContainer);

            inBody.Emit(OpCodes.Ldarg_0);
            inBody.Emit(OpCodes.Newobj, declaration.TypeParameters.Any()
                ? TypeBuilder.GetConstructor(
                    OutFunction.MakeGenericType(genericParameters),
                    OutFunctionConstructor)
                : OutFunctionConstructor);
            inBody.Emit(OpCodes.Call, fmap.MakeGenericMethod(new Type[] { fLeastFixedPoint, inputParameter }.Concat(genericParameters).ToArray()));
            inBody.Emit(OpCodes.Callvirt, declaration.TypeParameters.Any()
                ? TypeBuilder.GetMethod(inputParameter, Cata).MakeGenericMethod(fLeastFixedPoint)
                : Cata.MakeGenericMethod(fLeastFixedPoint));
            inBody.Emit(OpCodes.Ret);
        }
开发者ID:paf31,项目名称:Purity,代码行数:30,代码来源:LFixCompiler.cs

示例11: PreBuild

 protected override void PreBuild()
 {
     if (Info != null)
     {
         return;
     }
     var cont = CurrentContainer;
     Builder = cont.CreateMethod(Name, Attributes);
     Info = Builder;
     if (Generics.Count > 0)
     {
         var gb = Builder.DefineGenericParameters(Generics.ToNames());
         Generics.RegisterBuilders(gb);
     }
     if (ReturnType != null)
     {
         Builder.SetReturnType(ReturnType.GainType()); //todo ジェネリクスに対応したTypeを生成する。
     }
     Builder.SetParameters(Arguments.ToTypes());
     Arguments.RegisterBuilders(Builder, IsInstance);
     SpreadGenerator();
 }
开发者ID:B-head,项目名称:Dreit-prototype,代码行数:22,代码来源:MethodStructure.cs

示例12: ProcessReturnParameterAttributes

 /// <summary>
 /// Copies return type attributes to the new type.
 /// </summary>
 /// <param name="method"></param>
 /// <param name="invokeMethod"></param>
 private static void ProcessReturnParameterAttributes(MethodInfo method, MethodBuilder invokeMethod)
 {
     invokeMethod.SetReturnType(method.ReturnType);
     if (method.ReturnParameter != null)
     {
         var returnParameter = invokeMethod.DefineParameter(0, method.ReturnParameter.Attributes,
             method.ReturnParameter.Name);
         CopyParameterAttributes(returnParameter, method.ReturnParameter);
     }
 }
开发者ID:GeirGrusom,项目名称:PlatformInvoker,代码行数:15,代码来源:DelegateTypeBuilder.cs


注:本文中的System.Reflection.Emit.MethodBuilder.SetReturnType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。