當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。