コード例 #1
0
        protected override object[] ProcessParameters(string[] commandTerms)
        {
            Assert.IsNotNull(commandTerms);

            int paramIdx = GetParamStartTermIdx();

            if (commandTerms.Length > paramIdx)
            {
                return new object[] { StringTypeConverter.ToType(commandTerms[paramIdx], GetPropertyType()) }
            }
            ;
            else
            {
                return(new object[0]);
            }
        }
コード例 #2
0
        protected override object[] ProcessParameters(string[] commandTerms)
        {
            Assert.IsNotNull(commandTerms);

            int termIdx = GetParamStartTermIdx();

            ParameterInfo[] parameterInfos = _Method.GetParameters();
            int             numParams      = parameterInfos.Length;
            var             parameters     = new object[numParams];

            for (int i = 0; i < numParams; i++, termIdx++)
            {
                Type parameterType = parameterInfos[i].ParameterType;

                if (termIdx >= commandTerms.Length)
                {
                    // No user param defined, but this shouldn't be necessary to handle explicitly
                    // possibly once we hit the first optional param we can assume all are optional afterwards and resize the array?

                    if (parameterInfos[i].IsOptional)
                    {
                        parameters[i] = parameterInfos[i].RawDefaultValue;
                    }
                    else
                    {
                        parameters[i] = parameterType.IsValueType ? Activator.CreateInstance(parameterType) : null;
                    }
                }
                else
                {
                    parameters[i] = StringTypeConverter.ToType(commandTerms[termIdx], parameterType);
                }
            }

            return(parameters);
        }