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


C# IMethodInfo.GetGenericArguments方法代码示例

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


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

示例1: GetTypeFromGenericArgumentReferenceType

        private static ITypeInfo GetTypeFromGenericArgumentReferenceType(IMetadataGenericArgumentReferenceType reference, ITypeInfo typeInfo, IMethodInfo methodInfo)
        {
            var argument = reference.Argument;
            switch (argument.Kind)
            {
                case GenericArgumentKind.Type:
                    return typeInfo.GetGenericArguments().ToList()[(int)argument.Index];

                case GenericArgumentKind.Method:
                    return methodInfo.GetGenericArguments().ToList()[(int)argument.Index];
            }

            return null;
        }
开发者ID:Booksbaum,项目名称:resharper-xunit,代码行数:14,代码来源:MetadataTypeSystem.cs

示例2: ObtainMethod

		private static IMethodInfo ObtainMethod(IMethodInfo proxiedMethod, Type type)
		{
			Type[] genericArguments = null;
			if (proxiedMethod.IsGenericMethod)
			{
				genericArguments = proxiedMethod.GetGenericArguments();
				proxiedMethod = proxiedMethod.GetGenericMethodDefinition();
			}
			var declaringType = proxiedMethod.DeclaringType;
			IMethodInfo methodOnTarget = null;
			if (declaringType.IsInterface())
			{
				var mapping = type.GetInterfaceMap(declaringType);
				var index = Array.IndexOf(mapping.InterfaceMethods, proxiedMethod);
				Debug.Assert(index != -1);
				methodOnTarget = mapping.TargetMethods[index].AsIMethodInfo();
			}
			else
			{
				// NOTE: this implementation sucks, feel free to improve it.
				var methods = MethodFinder.GetAllInstanceMethods(type, BindingFlags.Public | BindingFlags.NonPublic);
				foreach (var method in methods)
				{
					if (MethodSignatureComparer.Instance.Equals(method.GetBaseDefinition(), proxiedMethod))
					{
						methodOnTarget = method;
						break;
					}
				}
			}
			if (methodOnTarget == null)
			{
				throw new ArgumentException(
					string.Format("Could not find method overriding {0} on type {1}. This is most likely a bug. Please report it.",
					              proxiedMethod, type));
			}

			if (genericArguments == null)
			{
				return methodOnTarget;
			}
			return methodOnTarget.MakeGenericMethod(genericArguments);
		}
开发者ID:rajgit31,项目名称:MetroUnitTestsDemoApp,代码行数:43,代码来源:InvocationHelper.cs

示例3: BuildFrom

        /// <summary>
        /// Construct one or more TestMethods from a given MethodInfo,
        /// using available parameter data.
        /// </summary>
        /// <param name="method">The MethodInfo for which tests are to be constructed.</param>
        /// <param name="suite">The suite to which the tests will be added.</param>
        /// <returns>One or more TestMethods</returns>
        public IEnumerable<TestMethod> BuildFrom(IMethodInfo method, Test suite)
        {
            List<TestMethod> tests = new List<TestMethod>();

#if NETCF
            if (method.ContainsGenericParameters)
            {
                var genericParams = method.GetGenericArguments();
                var numGenericParams = genericParams.Length;

                var o = new object();
                var tryArgs = Enumerable.Repeat(o, numGenericParams).ToArray();
                IMethodInfo mi;

                try
                {
                    // This fails if the generic method has constraints
                    // that are not met by object.
                    mi = method.MakeGenericMethodEx(tryArgs);
                    if (mi == null)
                        return tests;
                }
                catch
                {
                    return tests;
                }

                var par = mi.GetParameters();

                if (par.Length == 0)
                    return tests;

                var sourceData = par.Select(p => _dataProvider.GetDataFor(p)).ToArray();
                foreach (var parms in _strategy.GetTestCases(sourceData))
                {
                    mi = method.MakeGenericMethodEx(parms.Arguments);
                    if (mi == null)
                    {
                        var tm = new TestMethod(method, suite);
                        tm.RunState = RunState.NotRunnable;
                        tm.Properties.Set(PropertyNames.SkipReason, "Incompatible arguments");
                        tests.Add(tm);
                    }
                    else
                        tests.Add(_builder.BuildTestMethod(mi, suite, (TestCaseParameters)parms));
                }

                return tests;
            }
#endif
            IParameterInfo[] parameters = method.GetParameters();

            if (parameters.Length > 0)
            {
                IEnumerable[] sources = new IEnumerable[parameters.Length];

                try
                {
                    for (int i = 0; i < parameters.Length; i++)
                        sources[i] = _dataProvider.GetDataFor(parameters[i]);
                }
                catch (InvalidDataSourceException ex)
                {
                    var parms = new TestCaseParameters();
                    parms.RunState = RunState.NotRunnable;
                    parms.Properties.Set(PropertyNames.SkipReason, ex.Message);
                    tests.Add(_builder.BuildTestMethod(method, suite, parms));
                    return tests;
                }

                foreach (var parms in _strategy.GetTestCases(sources))
                    tests.Add(_builder.BuildTestMethod(method, suite, (TestCaseParameters)parms));
            }

            return tests;
        }
开发者ID:roboticai,项目名称:nunit,代码行数:83,代码来源:CombiningStrategyAttribute.cs

示例4: ResolveGenericTypes

        /// <summary>
        /// FOR INTERNAL USE ONLY.
        /// </summary>
        protected static ITypeInfo[] ResolveGenericTypes(IMethodInfo method, object[] parameters)
        {
            ITypeInfo[] genericTypes = method.GetGenericArguments().ToArray();
            ITypeInfo[] resolvedTypes = new ITypeInfo[genericTypes.Length];
            IParameterInfo[] parameterInfos = method.GetParameters().ToArray();

            for (int idx = 0; idx < genericTypes.Length; ++idx)
                resolvedTypes[idx] = ResolveGenericType(genericTypes[idx], parameters, parameterInfos);

            return resolvedTypes;
        }
开发者ID:valmaev,项目名称:xunit,代码行数:14,代码来源:XunitTestCase.cs

示例5: CopyGenericArguments

		private static GenericTypeParameterBuilder[] CopyGenericArguments(
			IMethodInfo methodToCopyGenericsFrom,
			Dictionary<String, GenericTypeParameterBuilder> name2GenericType,
			ApplyGenArgs genericParameterGenerator)
		{
			var originalGenericArguments = methodToCopyGenericsFrom.GetGenericArguments();
			if (originalGenericArguments.Length == 0)
			{
				return null;
			}

			var argumentNames = GetArgumentNames(originalGenericArguments);
			var newGenericParameters = genericParameterGenerator(argumentNames);

			for (var i = 0; i < newGenericParameters.Length; i++)
			{
				try
				{
					var attributes = originalGenericArguments[i].GenericParameterAttributes();
					newGenericParameters[i].SetGenericParameterAttributes(attributes);
					var constraints = AdjustGenericConstraints(methodToCopyGenericsFrom, newGenericParameters, originalGenericArguments, originalGenericArguments[i].GetGenericParameterConstraints());

					newGenericParameters[i].SetInterfaceConstraints(constraints);
					CopyNonInheritableAttributes(newGenericParameters[i], originalGenericArguments[i]);
				}
				catch (NotSupportedException)
				{
					// Doesnt matter

					newGenericParameters[i].SetGenericParameterAttributes(GenericParameterAttributes.None);
				}

				name2GenericType[argumentNames[i]] = newGenericParameters[i];
			}

			return newGenericParameters;
		}
开发者ID:rajgit31,项目名称:MetroUnitTestsDemoApp,代码行数:37,代码来源:GenericUtil.cs


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