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


C# Reflection.GetGenericArguments方法代码示例

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


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

示例1: GetName

        string GetName(bcl.MethodBase method)
        {
            if (method.IsGenericMethod)
            {
                var genericArgs = method.GetGenericArguments();
                return method.Name + "<" + string.Join(", ", genericArgs.Select(TypeUtils.ToFriendlyName)) + ">";
            }

            return method.Name;
        }
开发者ID:niik,项目名称:RxSpy,代码行数:10,代码来源:MethodInfo.cs

示例2: ImportMethodSpecification

		MethodReference ImportMethodSpecification (SR.MethodBase method, IGenericContext context)
		{
			var method_info = method as SR.MethodInfo;
			if (method_info == null)
				throw new InvalidOperationException ();

			var element_method = ImportMethod (method_info.GetGenericMethodDefinition (), context, ImportGenericKind.Definition);
			var instance = new GenericInstanceMethod (element_method);
			var arguments = method.GetGenericArguments ();
			var instance_arguments = instance.GenericArguments;

			for (int i = 0; i < arguments.Length; i++)
				instance_arguments.Add (ImportType (arguments [i], context ?? element_method));

			return instance;
		}
开发者ID:jeroldhaas,项目名称:ContinuousTests,代码行数:16,代码来源:Import.cs

示例3: ImportMethod

		public MethodReference ImportMethod (SR.MethodBase method, IGenericContext context, ImportGenericKind import_kind)
		{
			if (IsMethodSpecification (method) || ImportOpenGenericMethod (method, import_kind))
				return ImportMethodSpecification (method, context);

			var declaring_type = ImportType (method.DeclaringType, context);

			if (IsGenericInstance (method.DeclaringType))
				method = method.Module.ResolveMethod (method.MetadataToken);

			var reference = new MethodReference {
				Name = method.Name,
				HasThis = HasCallingConvention (method, SR.CallingConventions.HasThis),
				ExplicitThis = HasCallingConvention (method, SR.CallingConventions.ExplicitThis),
				DeclaringType = ImportType (method.DeclaringType, context, ImportGenericKind.Definition),
			};

			if (HasCallingConvention (method, SR.CallingConventions.VarArgs))
				reference.CallingConvention &= MethodCallingConvention.VarArg;

			if (method.IsGenericMethod)
				ImportGenericParameters (reference, method.GetGenericArguments ());

			var method_info = method as SR.MethodInfo;
			reference.ReturnType = method_info != null
				? ImportType (method_info.ReturnType, context ?? reference)
				: ImportType (typeof (void), null);

			var parameters = method.GetParameters ();
			var reference_parameters = reference.Parameters;

			for (int i = 0; i < parameters.Length; i++)
				reference_parameters.Add (
					new ParameterDefinition (ImportType (parameters [i].ParameterType, context ?? reference)));

			reference.DeclaringType = declaring_type;

			return reference;
		}
开发者ID:jeroldhaas,项目名称:ContinuousTests,代码行数:39,代码来源:Import.cs

示例4: FindMatchingMethodByName

        private SR.MethodBase FindMatchingMethodByName(Type targetType, SR.MethodInfo injectionMethod, string methodName)
        {
            var pars = injectionMethod.GetParameters();
            var genArgs = injectionMethod.GetGenericArguments();

            // Handle generic parameters
            Func<Type, Type> rMapper = (injParamType) =>
            {
                var mappedType = TryMapTypeToTargetAssemblyType(targetType.Assembly, injParamType);
                return mappedType != null ? mappedType : injParamType;
            };

            foreach (var m in targetType.GetMethodsAndCtors(BINDING_FLAGS))
            {
                if (m.Name != methodName)
                    continue;

                var mParams = m.GetParameters();
                if (mParams.Length != pars.Length)
                    continue;

                if (!mParams.Zip(pars, (p1, p2) => new { P1 = p1, P2 = p2 }).All(a => a.P1.ParameterMatches(a.P2, rMapper)))
                    continue;

                if (!m.IsConstructor)
                {
                    var mGenArgs = m.GetGenericArguments();
                    if (mGenArgs.Length != genArgs.Length)
                        continue;
                }

                return m;
            }

            return null;
        }
开发者ID:MarkusSintonen,项目名称:MNetInjector,代码行数:36,代码来源:Injector.cs

示例5: MethodMatches

        public static bool MethodMatches(this MethodReference method, SR.MethodBase matches)
        {
            if (method.Name != matches.Name)
                return false;

            if (matches is SR.MethodInfo)
            {
                if (!method.ReturnType.TypeMatches(((SR.MethodInfo)matches).ReturnType))
                    return false;
            }

            var m1Params = method.Parameters;
            var m2Params = matches.GetParameters();

            if (m1Params.Count != m2Params.Length)
                return false;

            for (var i = 0; i < m1Params.Count; i++)
            {
                if (!m1Params[i].ParameterMatches(m2Params[i]))
                    return false;
            }

            if (!matches.IsConstructor)
            {
                var m1GenericArgs = method.Resolve().GenericParameters;
                var m2GenericArgs = matches.GetGenericArguments();

                if (m1GenericArgs.Count != m2GenericArgs.Length) // No need to check types or constraints, no overloading for these in C#
                    return false;
            }

            return true;
        }
开发者ID:MarkusSintonen,项目名称:MNetInjector,代码行数:34,代码来源:Extensions.cs

示例6: ImportMethodSpecification

        MethodReference ImportMethodSpecification(SR.MethodBase method, Mono.Collections.Generic.Collection<IGenericParameterProvider> context)
        {
            var method_info = method as SR.MethodInfo;
            if (method_info == null)
                throw new InvalidOperationException ();

            var element_method = ImportMethod (method_info.GetGenericMethodDefinition (), context, ImportGenericKind.Definition);
            var instance = new GenericInstanceMethod (element_method);
            var arguments = method.GetGenericArguments ();
            var instance_arguments = instance.GenericArguments;

            AddToContext(ref context, element_method);
            try
            {
                for (int i = 0; i < arguments.Length; i++)
                    instance_arguments.Add(ImportType(arguments[i], context));

                return instance;
            }
            finally
            {
                RemoveFromContext(context);
            }
        }
开发者ID:keremkusmezer,项目名称:cecil,代码行数:24,代码来源:Import.cs


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