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


C# MethodBuilder.DefineGenericParameters方法代码示例

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


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

示例1: SetupParameters

        public void SetupParameters(MethodBuilder methodBuilder)
        {
            if (methodToOverride.IsGenericMethod)
            {
                Type[] genericArguments = methodToOverride.GetGenericArguments();
                string[] names = genericArguments
                    .Select(t => t.Name)
                    .ToArray();
                GenericTypeParameterBuilder[] builders = methodBuilder.DefineGenericParameters(names);
                for (int i = 0; i < genericArguments.Length; ++i)
                {
                    builders[i].SetGenericParameterAttributes(genericArguments[i].GenericParameterAttributes);

                    var constraintTypes = genericArguments[i].GetGenericParameterConstraints();

                    builders[i].SetInterfaceConstraints(constraintTypes.Where(t => t.IsInterface).ToArray());
                    foreach (Type type in constraintTypes.Where(t => !t.IsInterface))
                    {
                        builders[i].SetBaseTypeConstraint(type);
                    }
                }
                for(int i = 0; i < genericArguments.Length; ++i)
                {
                    genericMethodParameters.Add(new KeyValuePair<Type, Type>(genericArguments[i], builders[i].UnderlyingSystemType));
                }
            }
        }
开发者ID:shhyder,项目名称:MapApplication,代码行数:27,代码来源:MethodOverrideParameterMapper.cs

示例2: CloneGenericMethodArguments

        protected static GenericTypeParameterBuilder[] CloneGenericMethodArguments(MethodInfo source, MethodBuilder destination)
        {
            var genericArgs = source.GetGenericArguments();

            if (genericArgs.Length == 0)
            {
                return new GenericTypeParameterBuilder[0];
            }

            var names = new string[genericArgs.Length];

            for (var i = 0; i < genericArgs.Length; i++)
            {
                names[i] = genericArgs[i].Name;
            }

            var genericTypeParameterBuilders = destination.DefineGenericParameters(names);

            for (var i = 0; i < genericTypeParameterBuilders.Length; i++)
            {
                var genericArgConstraints = genericArgs[i].GetGenericParameterConstraints();

                for (var j = 0; j < genericArgConstraints.Length; j++)
                {
                    genericTypeParameterBuilders[i].SetBaseTypeConstraint(genericArgConstraints[j]);
                }
            }

            return genericTypeParameterBuilders;
        }
开发者ID:bradleyjford,项目名称:inception,代码行数:30,代码来源:MethodGenerator.cs

示例3: CopyGenericArguments

		public static GenericTypeParameterBuilder[] CopyGenericArguments(
			MethodInfo methodToCopyGenericsFrom, 
			MethodBuilder builder,
			Dictionary<String, GenericTypeParameterBuilder> name2GenericType)
		{
			return
				CopyGenericArguments(methodToCopyGenericsFrom, name2GenericType,
				                       delegate(String[] args) { return builder.DefineGenericParameters(args); });
		}
开发者ID:JulianBirch,项目名称:Castle.Core,代码行数:9,代码来源:GenericUtil.cs

示例4: DefineGenericArguments

		public static GenericTypeParameterBuilder[] DefineGenericArguments(
			Type[] genericArguments,
			MethodBuilder builder,
			Dictionary<String, GenericTypeParameterBuilder>
				name2GenericType)
		{
			return
				DefineGenericArguments(genericArguments, name2GenericType,
				                       delegate(String[] args) { return builder.DefineGenericParameters(args); });
		}
开发者ID:ralescano,项目名称:castle,代码行数:10,代码来源:GenericUtil.cs

示例5: CopyGenericSignature

        /// <summary>
        /// Copy the generic attributes of a method.
        /// </summary>
        /// <param name="sourceMethod">The source method.</param>
        /// <param name="targetMethod">The target method.</param>
        internal static void CopyGenericSignature(MethodInfo sourceMethod, MethodBuilder targetMethod)
        {
            if (sourceMethod.IsGenericMethod)
            {
                // get the interface's generic types and make our own
                var oldTypes = sourceMethod.GetGenericArguments();
                var newTypes = targetMethod.DefineGenericParameters(oldTypes.Select(t => t.Name).ToArray());
                for (int i = 0; i < newTypes.Length; i++)
                {
                    var oldType = oldTypes[i];
                    var newType = newTypes[i];

                    newType.SetGenericParameterAttributes(oldType.GenericParameterAttributes);
                    newType.SetInterfaceConstraints(oldType.GetGenericParameterConstraints());
                }
            }
        }
开发者ID:jamezor,项目名称:EventSourceProxy,代码行数:22,代码来源:ProxyHelper.cs

示例6: SetupParameters

        public void SetupParameters(MethodBuilder methodBuilder, GenericParameterMapper parentMapper)
        {
            if (methodToOverride.IsGenericMethod)
            {
                var genericArguments = methodToOverride.GetGenericArguments();
                var names = genericArguments.Select(t => t.Name).ToArray();
                var builders = methodBuilder.DefineGenericParameters(names);
                for (int i = 0; i < genericArguments.Length; ++i)
                {
                    builders[i].SetGenericParameterAttributes(genericArguments[i].GenericParameterAttributes);

                    var constraintTypes =
                        genericArguments[i]
                            .GetGenericParameterConstraints()
                            .Select(ct => parentMapper.Map(ct))
                            .ToArray();

                    var interfaceConstraints = constraintTypes.Where(t => t.IsInterface).ToArray();
                    Type baseConstraint = constraintTypes.Where(t => !t.IsInterface).FirstOrDefault();
                    if (baseConstraint != null)
                    {
                        builders[i].SetBaseTypeConstraint(baseConstraint);
                    }
                    if (interfaceConstraints.Length > 0)
                    {
                        builders[i].SetInterfaceConstraints(interfaceConstraints);
                    }
                }

                this.genericParameterMapper =
                    new GenericParameterMapper(genericArguments, builders.Cast<Type>().ToArray(), parentMapper);
            }
            else
            {
                this.genericParameterMapper = parentMapper;
            }
        }
开发者ID:kangkot,项目名称:unity,代码行数:37,代码来源:MethodOverrideParameterMapper.cs

示例7: 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

示例8: DefineGenericParameters

        private GenericTypeParameterBuilder[] DefineGenericParameters(TypeBuilder typeBuilder, MethodBuilder methodBuilder, IEnumerable<Cci.IGenericParameter> typeParameters)
        {
            Debug.Assert(typeBuilder != null ^ methodBuilder != null);

            var names = new List<string>(typeParameters.Select(typeParameter => typeParameter.Name)).ToArray();
            var gpBuilders = (typeBuilder != null) ? typeBuilder.DefineGenericParameters(names) : methodBuilder.DefineGenericParameters(names);

            int i = 0;
            foreach (var typeParameter in typeParameters)
            {
                _genericParameterBuilders.Add(typeParameter, gpBuilders[i++]);
            }

            return gpBuilders;
        }
开发者ID:furesoft,项目名称:roslyn,代码行数:15,代码来源:ReflectionEmitter.cs

示例9: DefineStubGenericParameters

		/// <summary>
		/// Defines generic parameters according to the given template and re-maps relevant parameters.
		/// </summary>
		public static void DefineStubGenericParameters(MethodBuilder/*!*/ stub, Type[]/*!!*/ genericParameters,
			PhpRoutineSignature/*!*/ targetSignature, Type[]/*!!*/ parameters)
		{
			// determine generic parameter names
			string[] generic_param_names = new string[genericParameters.Length];
			for (int j = 0; j < generic_param_names.Length; j++)
			{
				if (j < targetSignature.GenericParamCount)
				{
					generic_param_names[j] = targetSignature.GenericParams[j].Name.ToString();
				}
				else generic_param_names[j] = genericParameters[j].Name;
			}
			GenericTypeParameterBuilder[] generic_params = stub.DefineGenericParameters(generic_param_names);

			// determine generic parameter attributes and constraints
			for (int j = 0; j < generic_params.Length; j++)
			{
				Type template_type = genericParameters[j];

				// attributes
				generic_params[j].SetGenericParameterAttributes(template_type.GenericParameterAttributes);

				// constraints
				Type[] template_constraints = template_type.GetGenericParameterConstraints();

				List<Type> interface_constraints = new List<Type>();
				for (int k = 0; k < template_constraints.Length; k++)
				{
					if (template_constraints[k].IsClass) generic_params[j].SetBaseTypeConstraint(template_constraints[k]);
					else interface_constraints.Add(template_constraints[k]);
				}
				generic_params[j].SetInterfaceConstraints(interface_constraints.ToArray());
			}

			// re-map base method generic parameters to the newly defined generic parameters
			for (int j = 0; j < parameters.Length; j++)
			{
				if (parameters[j].IsGenericParameter && parameters[j].DeclaringMethod != null)
				{
					// method generic parameter
					parameters[j] = generic_params[parameters[j].GenericParameterPosition];
				}
			}
		}
开发者ID:dw4dev,项目名称:Phalanger,代码行数:48,代码来源:ClrStubBuilder.cs

示例10: HandleGenericMethodArguments

        private static void HandleGenericMethodArguments(MethodInfo targetMethod, MethodBuilder method)
        {
            if (targetMethod.ContainsGenericParameters)
            {
                var genericArguments = targetMethod.GetGenericArguments();
                var genericParameters = method.DefineGenericParameters(
                    Array.ConvertAll<Type, string>(genericArguments,
                        new Converter<Type, string>(target => { return target.Name; })));

                for (var i = 0; i < genericParameters.Length; i++)
                {
                    var genericParameter = genericParameters[i];
                    var genericArgument = genericArguments[i];
                    genericParameter.SetGenericParameterAttributes(
                        genericArgument.GenericParameterAttributes);
                    var interfaceConstraints = new List<Type>();
                    Type baseTypeConstraint = null;

                    foreach (Type typeConstraint in genericArgument.GetGenericParameterConstraints())
                    {
                        if (typeConstraint.IsClass)
                        {
                            baseTypeConstraint = typeConstraint;
                        }
                        else
                        {
                            interfaceConstraints.Add(typeConstraint);
                        }
                    }

                    if (baseTypeConstraint != null)
                    {
                        genericParameter.SetBaseTypeConstraint(baseTypeConstraint);
                    }

                    if (interfaceConstraints.Count > 0)
                    {
                        genericParameter.SetInterfaceConstraints(interfaceConstraints.ToArray());
                    }
                }
            }

            for (var i = 0; i < targetMethod.GetParameters().Length; i++)
            {
                var parameterInfo = targetMethod.GetParameters()[i];
                method.DefineParameter(i + 1, parameterInfo.Attributes, parameterInfo.Name);
            }
        }
开发者ID:JasonBock,项目名称:DynamicProxies,代码行数:48,代码来源:ProxyMethodBuilder.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: 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

示例13: DefineGenericParameters

        /// <summary>
        /// Defines generic method parameters based on proxied method metadata.
        /// </summary>
        /// <param name="methodBuilder">
        /// The <see cref="System.Reflection.Emit.MethodBuilder"/> to use.
        /// </param>
        /// <param name="method">The method to proxy.</param>
        protected void DefineGenericParameters(MethodBuilder methodBuilder, MethodInfo method)
        {
            if (method.IsGenericMethodDefinition)
            {
                Type[] genericArguments = method.GetGenericArguments();

                // define generic parameters
                GenericTypeParameterBuilder[] gtpBuilders =
                    methodBuilder.DefineGenericParameters(ReflectionUtils.GetGenericParameterNames(genericArguments));

                // define constraints for each generic parameter
                for (int i = 0; i < genericArguments.Length; i++)
                {
                    gtpBuilders[i].SetGenericParameterAttributes(genericArguments[i].GenericParameterAttributes);

                    Type[] constraints = genericArguments[i].GetGenericParameterConstraints();
                    System.Collections.Generic.List<Type> interfaces = new System.Collections.Generic.List<Type>(constraints.Length);
                    foreach (Type constraint in constraints)
                    {
                        if (constraint.IsClass)
                            gtpBuilders[i].SetBaseTypeConstraint(constraint);
                        else
                            interfaces.Add(constraint);
                    }
                    gtpBuilders[i].SetInterfaceConstraints(interfaces.ToArray());
                }
            }
        }
开发者ID:hazzik,项目名称:nh-contrib-everything,代码行数:35,代码来源:AbstractProxyMethodBuilder.cs

示例14: DefineMethodOverride

        protected ILGen DefineMethodOverride(MethodAttributes extra, MethodInfo decl, out MethodBuilder impl) {
            MethodAttributes finalAttrs = (decl.Attributes & ~(MethodAttributesToEraseInOveride)) | extra;
            if (!decl.DeclaringType.IsInterface) {
                finalAttrs &= ~MethodAttributes.NewSlot;
            }

            if ((extra & MethodAttributes.MemberAccessMask) != 0) {
                // remove existing member access, add new member access
                finalAttrs &= ~MethodAttributes.MemberAccessMask;
                finalAttrs |= extra;
            }
            Type[] signature = ReflectionUtils.GetParameterTypes(decl.GetParameters());
            impl = _tg.DefineMethod(decl.Name, finalAttrs, decl.ReturnType, signature);
            if (decl.IsGenericMethodDefinition) {
                Type[] args = decl.GetGenericArguments();
                string[] names = new string[args.Length];
                for (int i = 0; i < args.Length; i++) {
                    names[i] = args[i].Name;
                }
                var builders = impl.DefineGenericParameters(names);
                for (int i = 0; i < args.Length; i++) {
                    // Copy template parameter attributes
                    builders[i].SetGenericParameterAttributes(args[i].GenericParameterAttributes);

                    // Copy template parameter constraints
                    Type[] constraints = args[i].GetGenericParameterConstraints();
                    List<Type> interfaces = new List<Type>(constraints.Length);
                    foreach (Type constraint in constraints) {
                        if (constraint.IsInterface) {
                            interfaces.Add(constraint);
                        } else {
                            builders[i].SetBaseTypeConstraint(constraint);
                        }
                    }
                    if (interfaces.Count > 0) {
                        builders[i].SetInterfaceConstraints(interfaces.ToArray());
                    }
                }
            }
            return CreateILGen(impl.GetILGenerator());
        }
开发者ID:octavioh,项目名称:ironruby,代码行数:41,代码来源:NewTypeMaker.cs

示例15: 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


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