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


C# IMethodInfo.GetParameters方法代码示例

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


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

示例1: 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>();
            
            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:textmetal,项目名称:main,代码行数:37,代码来源:CombiningStrategyAttribute.cs

示例2: GetParametersForMethod

        private TestCaseParameters GetParametersForMethod(IMethodInfo method)
        {
            try
            {
                var parameterValues = this.CreateParameterValues(method.GetParameters());

                return new TestCaseParameters(parameterValues);
            }
            catch (Exception ex)
            {
                return new TestCaseParameters(ex);
            }
        }
开发者ID:SIXNetworks,项目名称:withSIX.Desktop,代码行数:13,代码来源:AutoDataAttribute.cs

示例3: GetParametersForMethod

 private TestCaseParameters GetParametersForMethod(IMethodInfo method)
 {
     try
     {
         var specimenBuilder = new SpecimenContext(this._fixture);
         var parameterValues = method.GetParameters()
             .Select(p => specimenBuilder.Resolve(p.ParameterInfo))
             .ToArray();
         return new TestCaseParameters(parameterValues);
     }
     catch (Exception ex)
     {
         return new TestCaseParameters(ex);
     }
 }
开发者ID:ErikSchierboom,项目名称:AutoFixture,代码行数:15,代码来源:AutoDataAttribute.cs

示例4: MethodEmitter

		internal MethodEmitter(AbstractTypeEmitter owner, String name,
		                       MethodAttributes attributes, IMethodInfo methodToUseAsATemplate)
			: this(owner, name, attributes)
		{
			var name2GenericType = GenericUtil.GetGenericArgumentsMap(owner);

			var returnType = GenericUtil.ExtractCorrectType(methodToUseAsATemplate.ReturnType, name2GenericType);
			var baseMethodParameters = methodToUseAsATemplate.GetParameters();
			var parameters = GenericUtil.ExtractParametersTypes(baseMethodParameters, name2GenericType);

			genericTypeParams = GenericUtil.CopyGenericArguments(methodToUseAsATemplate, builder, name2GenericType);
			SetParameters(parameters);
			SetReturnType(returnType);
			SetSignature(returnType, methodToUseAsATemplate.ReturnParameter, parameters, baseMethodParameters);
			DefineParameters(baseMethodParameters);
		}
开发者ID:rajgit31,项目名称:MetroUnitTestsDemoApp,代码行数:16,代码来源:MethodEmitter.cs

示例5: 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, Internal.Test suite)
        {
            IParameterInfo[] parameters = method.GetParameters();

            List<TestMethod> tests = new List<TestMethod>();

            if (parameters.Length > 0)
            {
                IEnumerable[] sources = new IEnumerable[parameters.Length];
                for (int i = 0; i < parameters.Length; i++)
                    sources[i] = _dataProvider.GetDataFor(parameters[i]);

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

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

示例6: GetDisplayNameWithArguments

        public static string GetDisplayNameWithArguments(IMethodInfo method, string baseDisplayName, object[] arguments, ITypeInfo[] genericTypes)
        {
            baseDisplayName += ResolveGenericDisplay(genericTypes);

            if (arguments == null)
                return baseDisplayName;

            var parameterInfos = method.GetParameters().ToArray();
            var displayValues = new string[Math.Max(arguments.Length, parameterInfos.Length)];
            int idx;

            for (idx = 0; idx < arguments.Length; idx++)
                displayValues[idx] = ParameterToDisplayValue(GetParameterName(parameterInfos, idx), arguments[idx]);

            for (; idx < parameterInfos.Length; idx++)  // Fill-in any missing parameters with "???"
                displayValues[idx] = GetParameterName(parameterInfos, idx) + ": ???";

            return String.Format(CultureInfo.CurrentCulture, "{0}({1})", baseDisplayName, string.Join(", ", displayValues));
        }
开发者ID:joaomajesus,项目名称:xunit,代码行数:19,代码来源:TypeUtility.cs

示例7: CopyOutAndRefParameters

		public static void CopyOutAndRefParameters(TypeReference[] dereferencedArguments, LocalReference invocation,
		                                           IMethodInfo method, MethodEmitter emitter)
		{
			var parameters = method.GetParameters();
			if (!ArgumentsUtil.IsAnyByRef(parameters))
			{
				return; //saving the need to create locals if there is no need
			}

			var arguments = StoreInvocationArgumentsInLocal(emitter, invocation);

			for (var i = 0; i < parameters.Length; i++)
			{
				if (!parameters[i].ParameterType.IsByRef)
				{
					continue;
				}

				emitter.CodeBuilder.AddStatement(AssignArgument(dereferencedArguments, i, arguments));
			}
		}
开发者ID:rajgit31,项目名称:MetroUnitTestsDemoApp,代码行数:21,代码来源:GeneratorUtil.cs

示例8: GetData

        /// <inheritdoc/>
        public virtual IEnumerable<object[]> GetData(IAttributeInfo dataAttribute, IMethodInfo testMethod)
        {
            // The data from GetConstructorArguments does not maintain its original form (in particular, collections
            // end up as generic IEnumerable<T>). So we end up needing to call .ToArray() on the enumerable so that
            // we can restore the correct argument type from InlineDataAttribute.
            //
            // In addition, [InlineData(null)] gets translated into passing a null array, not a single array with a null
            // value in it, which is why the null coalesce operator is required (this is covered by the acceptance test
            // in Xunit2TheoryAcceptanceTests.InlineDataTests.SingleNullValuesWork).
            var count = testMethod.GetParameters().Count();

            var arguments = dataAttribute.GetConstructorArguments();
            var args = (IEnumerable<object>)arguments.Single() ?? new object[] { null };
            var objects = args.ToArray();
            var results = objects.Select(x => Enumerable.Empty<object>().Concat(new[] { x }));

            while (--count > 0)
            {
                results = results.Join(objects, o => true, o => true, (enumerable, item) => enumerable.Concat(new[] { item }).ToArray());
            }

            var array = results.Select(x => x.ToArray()).ToArray();
            return array;
        }
开发者ID:kthompson,项目名称:zenos,代码行数:25,代码来源:PermuteDataAttribute.cs

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

示例10: GetParametersForTestCase

        private TestCaseParameters GetParametersForTestCase(IMethodInfo method)
        {
            TestCaseParameters parms;

            try
            {
#if NETCF
                var tmethod = method.MakeGenericMethodEx(Arguments);
                if (tmethod == null)
                    throw new NotSupportedException("Cannot determine generic types from probing");
                method = tmethod;
#endif

                IParameterInfo[] parameters = method.GetParameters();
                int argsNeeded = parameters.Length;
                int argsProvided = Arguments.Length;

                parms = new TestCaseParameters(this);

                // Special handling for params arguments
                if (argsNeeded > 0 && argsProvided >= argsNeeded - 1)
                {
                    IParameterInfo lastParameter = parameters[argsNeeded - 1];
                    Type lastParameterType = lastParameter.ParameterType;
                    Type elementType = lastParameterType.GetElementType();

                    if (lastParameterType.IsArray && lastParameter.IsDefined<ParamArrayAttribute>(false))
                    {
                        if (argsProvided == argsNeeded)
                        {
                            Type lastArgumentType = parms.Arguments[argsProvided - 1].GetType();
                            if (!lastParameterType.IsAssignableFrom(lastArgumentType))
                            {
                                Array array = Array.CreateInstance(elementType, 1);
                                array.SetValue(parms.Arguments[argsProvided - 1], 0);
                                parms.Arguments[argsProvided - 1] = array;
                            }
                        }
                        else
                        {
                            object[] newArglist = new object[argsNeeded];
                            for (int i = 0; i < argsNeeded && i < argsProvided; i++)
                                newArglist[i] = parms.Arguments[i];

                            int length = argsProvided - argsNeeded + 1;
                            Array array = Array.CreateInstance(elementType, length);
                            for (int i = 0; i < length; i++)
                                array.SetValue(parms.Arguments[argsNeeded + i - 1], i);

                            newArglist[argsNeeded - 1] = array;
                            parms.Arguments = newArglist;
                            argsProvided = argsNeeded;
                        }
                    }
                }

                //if (method.GetParameters().Length == 1 && method.GetParameters()[0].ParameterType == typeof(object[]))
                //    parms.Arguments = new object[]{parms.Arguments};

                // Special handling when sole argument is an object[]
                if (argsNeeded == 1 && method.GetParameters()[0].ParameterType == typeof(object[]))
                {
                    if (argsProvided > 1 ||
                        argsProvided == 1 && parms.Arguments[0].GetType() != typeof(object[]))
                    {
                        parms.Arguments = new object[] { parms.Arguments };
                    }
                }

                if (argsProvided == argsNeeded)
                    PerformSpecialConversions(parms.Arguments, parameters);
            }
            catch (Exception ex)
            {
                parms = new TestCaseParameters(ex);
            }

            return parms;
        }
开发者ID:roboticai,项目名称:nunit,代码行数:79,代码来源:TestCaseAttribute.cs

示例11: GetTestCasesFor

        /// <summary>
        /// Returns a set of ITestCaseDataItems for use as arguments
        /// to a parameterized test method.
        /// </summary>
        /// <param name="method">The method for which data is needed.</param>
        /// <returns></returns>
        private IEnumerable<ITestCaseData> GetTestCasesFor(IMethodInfo method)
        {
            List<ITestCaseData> data = new List<ITestCaseData>();

            try
            {
                IEnumerable source = GetTestCaseSource(method);

                if (source != null)
                {
                    foreach (object item in source)
                    {
                        // First handle two easy cases:
                        // 1. Source is null. This is really an error but if we
                        //    throw an exception we simply get an invalid fixture
                        //    without good info as to what caused it. Passing a
                        //    single null argument will cause an error to be 
                        //    reported at the test level, in most cases.
                        // 2. User provided an ITestCaseData and we just use it.
                        ITestCaseData parms = item == null
                            ? new TestCaseParameters(new object[] { null })
                            : item as ITestCaseData;

                        if (parms == null)
                        {
                            // 3. An array was passed, it may be an object[]
                            //    or possibly some other kind of array, which
                            //    TestCaseSource can accept.
                            var args = item as object[];
                            if (args == null && item is Array)
                            {
                                Array array = item as Array;
#if NETCF
                                bool netcfOpenType = method.IsGenericMethodDefinition;
#else
                                bool netcfOpenType = false;
#endif
                                int numParameters = netcfOpenType ? array.Length : method.GetParameters().Length;
                                if (array != null && array.Rank == 1 && array.Length == numParameters)
                                {
                                    // Array is something like int[] - convert it to
                                    // an object[] for use as the argument array.
                                    args = new object[array.Length];
                                    for (int i = 0; i < array.Length; i++)
                                        args[i] = array.GetValue(i);
                                }
                            }

                            // Check again if we have an object[]
                            if (args != null)
                            {
#if NETCF
                                if (method.IsGenericMethodDefinition)
                                {
                                    var mi = method.MakeGenericMethodEx(args);
                                    if (mi == null)
                                        throw new NotSupportedException("Cannot determine generic Type");
                                    method = mi;
                                }
#endif

                                var parameters = method.GetParameters();
                                var argsNeeded = parameters.Length;
                                var argsProvided = args.Length;
               
                                // If only one argument is needed, our array may actually
                                // be the bare argument. If it is, we should wrap it in
                                // an outer object[] representing the list of arguments.
                                if (argsNeeded == 1)
                                {
                                    var singleParmType = parameters[0].ParameterType;
                                    
                                    if (argsProvided == 0 || typeof(object[]).IsAssignableFrom(singleParmType))
                                    {
                                        if (argsProvided > 1 || singleParmType.IsAssignableFrom(args.GetType()))
                                        {
                                            args = new object[] { item };
                                        }
                                    }
                                }
                            }
                            else // It may be a scalar or a multi-dimensioned array. Wrap it in object[]
                            {
                                args = new object[] { item };
                            }

                            parms = new TestCaseParameters(args);
                        }

                        if (this.Category != null)
                            foreach (string cat in this.Category.Split(new char[] { ',' }))
                                parms.Properties.Add(PropertyNames.Category, cat);

                        data.Add(parms);
//.........这里部分代码省略.........
开发者ID:elv1s42,项目名称:nunit,代码行数:101,代码来源:TestCaseSourceAttribute.cs

示例12: GetTestCasesFor

        /// <summary>
        /// Returns a set of ITestCaseDataItems for use as arguments
        /// to a parameterized test method.
        /// </summary>
        /// <param name="method">The method for which data is needed.</param>
        /// <returns></returns>
        private IEnumerable<ITestCaseData> GetTestCasesFor(IMethodInfo method)
        {
            List<ITestCaseData> data = new List<ITestCaseData>();

            try
            {
                IEnumerable source = GetTestCaseSource(method);

                if (source != null)
                {
#if NETCF
                    int numParameters = method.IsGenericMethodDefinition ? 0 : method.GetParameters().Length;
#else
                    int numParameters = method.GetParameters().Length;
#endif

                    foreach (object item in source)
                    {
                        var parms = item as ITestCaseData;

                        if (parms == null)
                        {
                            object[] args = item as object[];
                            if (args != null)
                            {
#if NETCF
                                if (method.IsGenericMethodDefinition)
                                {
                                    var mi = method.MakeGenericMethodEx(args);
                                    numParameters = mi == null ? 0 : mi.GetParameters().Length;
                                }
#endif
                                if (args.Length != numParameters)//parameters.Length)
                                    args = new object[] { item };
                            }
                            else if (item is Array)
                            {
                                Array array = item as Array;

#if NETCF
                                if (array.Rank == 1 && (method.IsGenericMethodDefinition || array.Length == numParameters))//parameters.Length))
#else
                                if (array.Rank == 1 && array.Length == numParameters)//parameters.Length)
#endif
                                {
                                    args = new object[array.Length];
                                    for (int i = 0; i < array.Length; i++)
                                        args[i] = array.GetValue(i);
#if NETCF
                                    if (method.IsGenericMethodDefinition)
                                    {
                                        var mi = method.MakeGenericMethodEx(args);

                                        if (mi == null || array.Length != mi.GetParameters().Length)
                                            args = new object[] {item};
                                    }
#endif
                                }
                                else
                                {
                                    args = new object[] { item };
                                }
                            }
                            else
                            {
                                args = new object[] { item };
                            }

                            parms = new TestCaseParameters(args);
                        }

                        if (this.Category != null)
                            foreach (string cat in this.Category.Split(new char[] { ',' }))
                                parms.Properties.Add(PropertyNames.Category, cat);

                        data.Add(parms);
                    }
                }
            }
            catch (Exception ex)
            {
                data.Clear();
                data.Add(new TestCaseParameters(ex));
            }

            return data;
        }
开发者ID:alfeg,项目名称:nunit,代码行数:93,代码来源:TestCaseSourceAttribute.cs

示例13: FuzzyMethod

        private FuzzyMethod(FuzzyType target, IMethodInfo runtimeMethod)
        {
            _method = runtimeMethod;

            var genericArgs = new List<FuzzyType>();
            foreach (var genericArg in _method.GetMethodGenericArguments())
                genericArgs.Add(FuzzyType.FromRuntimeType(genericArg));
            GenericArguments = genericArgs.AsReadOnly();

            Target = target;
            ReturnValue = FuzzyType.FromRuntimeType(_method.ReturnType);
            Args = _method.GetParameters()
                .Select(param => FuzzyType.FromRuntimeType(param.ParameterType))
                .ToArray();

            // establishing links between typedef generic args and method's generic args
            // read more comments at FuzzyType.GetFieldOrProperty
            // see also comments to ReflectionHelper.GetGenericArgsMapping

            foreach (var pair in _method.GetGenericArgsMapping())
            {
                var typeDefArg = SelectGenericArg(pair.Value);
                var publicTypePointArgs = SelectGenericArg(pair.Key);
                publicTypePointArgs.IsIdenticalTo(typeDefArg);
            }

            // SomeMoreStuffInferred handlers for children just escalate the event
            // no need to process it since everything necessary is already done by links
            //
            // upd. currently noone cares about this event from this very class, 
            // but imo it's still important to comply to FuzzyMetadata contract

            Target.SomeMoreStuffInferred += (o, e) => FireSomeMoreStuffInferred();
            ReturnValue.SomeMoreStuffInferred += (o, e) => FireSomeMoreStuffInferred();
            Args.ForEach(arg => arg.SomeMoreStuffInferred += (o, e) => FireSomeMoreStuffInferred());

            // Register typepoints for debug -> 0 downtime in release, but immensely useful in debug mode
            var methodBinding = target.DebuggableParents.OfType<FuzzyMethodBinding>().SingleOrDefault();
            if (methodBinding != null)
            {
                this.RegDebuggableParent(methodBinding).SetDesc("alt");
                ReturnValue.RegDebuggableParent(this).SetDesc("ret");
                Args.ForEach((arg, i) => arg.RegDebuggableParent(this).SetDesc("arg" + i));
            }
        }
开发者ID:xeno-by,项目名称:relinq,代码行数:45,代码来源:FuzzyMethod.cs

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

示例15: GetParametersForTestCase

        private TestCaseParameters GetParametersForTestCase(IMethodInfo method)
        {
            TestCaseParameters parms;

            try
            {
                IParameterInfo[] parameters = method.GetParameters();
                int argsNeeded = parameters.Length;
                int argsProvided = Arguments.Length;

                parms = new TestCaseParameters(this);

                // Special handling for params arguments
                if (argsNeeded > 0 && argsProvided >= argsNeeded - 1)
                {
                    IParameterInfo lastParameter = parameters[argsNeeded - 1];
                    Type lastParameterType = lastParameter.ParameterType;
                    Type elementType = lastParameterType.GetElementType();

                    if (lastParameterType.IsArray && lastParameter.IsDefined<ParamArrayAttribute>(false))
                    {
                        if (argsProvided == argsNeeded)
                        {
                            Type lastArgumentType = parms.Arguments[argsProvided - 1].GetType();
                            if (!lastParameterType.GetTypeInfo().IsAssignableFrom(lastArgumentType.GetTypeInfo()))
                            {
                                Array array = Array.CreateInstance(elementType, 1);
                                array.SetValue(parms.Arguments[argsProvided - 1], 0);
                                parms.Arguments[argsProvided - 1] = array;
                            }
                        }
                        else
                        {
                            object[] newArglist = new object[argsNeeded];
                            for (int i = 0; i < argsNeeded && i < argsProvided; i++)
                                newArglist[i] = parms.Arguments[i];

                            int length = argsProvided - argsNeeded + 1;
                            Array array = Array.CreateInstance(elementType, length);
                            for (int i = 0; i < length; i++)
                                array.SetValue(parms.Arguments[argsNeeded + i - 1], i);

                            newArglist[argsNeeded - 1] = array;
                            parms.Arguments = newArglist;
                            argsProvided = argsNeeded;
                        }
                    }
                }

                //Special handling for optional parameters
                if (parms.Arguments.Length < argsNeeded)
                {
                    object[] newArgList = new object[parameters.Length];
                    Array.Copy(parms.Arguments, newArgList, parms.Arguments.Length);

                    //Fill with Type.Missing for remaining required parameters where optional
                    for (var i = parms.Arguments.Length; i < parameters.Length; i++)
                    {
                        if (parameters[i].IsOptional)
                            newArgList[i] = Type.Missing;
                        else
                        {
                            if (i < parms.Arguments.Length)
                                newArgList[i] = parms.Arguments[i];
                            else
                                throw new TargetParameterCountException(string.Format(
                                    "Method requires {0} arguments but TestCaseAttribute only supplied {1}",
                                    argsNeeded, 
                                    argsProvided));
                        }
                    }
                    parms.Arguments = newArgList;
                }

                //if (method.GetParameters().Length == 1 && method.GetParameters()[0].ParameterType == typeof(object[]))
                //    parms.Arguments = new object[]{parms.Arguments};

                // Special handling when sole argument is an object[]
                if (argsNeeded == 1 && method.GetParameters()[0].ParameterType == typeof(object[]))
                {
                    if (argsProvided > 1 ||
                        argsProvided == 1 && parms.Arguments[0].GetType() != typeof(object[]))
                    {
                        parms.Arguments = new object[] { parms.Arguments };
                    }
                }

                if (argsProvided == argsNeeded)
                    PerformSpecialConversions(parms.Arguments, parameters);
            }
            catch (Exception ex)
            {
                parms = new TestCaseParameters(ex);
            }

            return parms;
        }
开发者ID:nunit,项目名称:nunit,代码行数:97,代码来源:TestCaseAttribute.cs


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