private void MapArgumentsByPosition(Route source, ParameterInfo[] requiredArguments, NameValueCollection headers, int skipNumberOfDestinationArguments, List<KeyValuePair<Type, ParameterNameAndLocation>> map)
        {
            if ((requiredArguments.Length - skipNumberOfDestinationArguments) != source.QueryParameters.Count() + source.RouteParameters.Count())
                throw new InvalidOperationException("Either use parameter names mathing the query and route parameters or specify as many parameters as the combined number of route and query variables");

            IEnumerator headerParameters = headers.AllKeys.GetEnumerator();
            IEnumerator<string> routeParameters = source.RouteParameters.GetEnumerator();
            IEnumerator<string> queryParameters = source.QueryParameters.GetEnumerator();

            foreach (ParameterInfo argument in requiredArguments.Skip(skipNumberOfDestinationArguments))
            {
                if (headerParameters.MoveNext())
                {
                    object value = RouteHelpers.GetHeaderParameterValue((string)headerParameters.Current, headers, argument.ParameterType);

                    if (value != null)
                    {
                        map.Add(new KeyValuePair<Type, ParameterNameAndLocation>(argument.ParameterType,
                                                                                                                                  new ParameterNameAndLocation { Name = routeParameters.Current, Location = ParameterLocation.Header }));
                    }
                }

                if (routeParameters.MoveNext())
                {
                    map.Add(new KeyValuePair<Type, ParameterNameAndLocation>(argument.ParameterType,
                                                                                                                              new ParameterNameAndLocation{ Name = routeParameters.Current, Location = ParameterLocation.Route }));
                }
                else
                {
                    queryParameters.MoveNext();
                    map.Add(new KeyValuePair<Type, ParameterNameAndLocation>(argument.ParameterType,
                                                                                                                              new ParameterNameAndLocation{ Name = queryParameters.Current, Location = ParameterLocation.Query }));
                }
            }
        }
예제 #2
0
		public static string GetParametersShortSignature(ParameterInfo[] pars, int skipCount = 0)
		{
			if (pars.Length < 1 + skipCount)
				return "";
			return "(" +
				pars
				.Skip(skipCount)
				.Select(_ => TypeUtils.ToDisplayString(_.ParameterType, false))
				.Aggregate((s1, s2) => s1 + ", " + s2)
			+ ")";
		}
예제 #3
0
		public static XElement GetParametersLongSignature(ParameterInfo[] pars, int skipCount = 0)
		{
			if (pars.Length < 1+skipCount)
				return new XElement("span");

			var args = pars
				.Skip(skipCount)
				.SelectMany(p => new[]
				{
					GenerateHtml.BuildTypeUrl(p.ParameterType, false),
					new XElement("span", ","), 
				})
				.ToArray();

			return new XElement("span", new XElement("span", "("), args.Take(args.Count() - 1), new XElement("span", ")"));
		}
예제 #4
0
파일: CommandTarget.cs 프로젝트: rsdn/janus
		private static void CheckParameters(ICommandInfo commandInfo, ParameterInfo[] parameters)
		{
			if (parameters.Length < 1
					|| parameters[0].ParameterType != typeof(ICommandContext))
				throw new ApplicationException(
					"Отсутствует первый параметр, имеющий тип ICommandContext.");

			foreach (var methodParameter in parameters.Skip(1))
			{
				if (!commandInfo.IsParameterExists(methodParameter.Name))
					throw new ApplicationException($"Параметр '{methodParameter.Name}' не предусмотрен командой.");
				if (commandInfo.GetParameter(methodParameter.Name).IsOptional
						&& methodParameter.ParameterType.IsValueType
						&& methodParameter.ParameterType == typeof(Nullable<>))
					throw new ApplicationException(
						$"Необязательный параметр '{methodParameter.Name}' должен иметь ссылочный тип.");
			}
		}
예제 #5
0
        private bool TryWrappedInvokeOrInvokeMember(DynamicMetaObjectBinder binder, ParameterInfo[] parameters, object[] args, out object result)
        {
            Type[] paramTypes = null;
            if ((parameters != null) && (parameters.Length >= args.Length))
            {
                paramTypes = parameters.Skip(parameters.Length - args.Length).Select(param => param.ParameterType).ToArray();
            }

            if (paramTypes != null)
            {
                for (var index = 0; index < paramTypes.Length; index++)
                {
                    var paramType = paramTypes[index];
                    if (paramType.IsByRef)
                    {
                        args[index] = typeof(HostVariable<>).MakeSpecificType(paramType.GetElementType()).CreateInstance(args[index]);
                    }
                }
            }

            if (TryWrappedBindAndInvoke(binder, AdjustInvokeArgs(args), out result))
            {
                if (paramTypes != null)
                {
                    for (var index = 0; index < paramTypes.Length; index++)
                    {
                        if (paramTypes[index].IsByRef)
                        {
                            var hostVariable = args[index] as IHostVariable;
                            if (hostVariable != null)
                            {
                                args[index] = hostVariable.Value;
                            }
                        }
                    }
                }

                return true;
            }

            return false;
        }
예제 #6
0
        void DefaultParamValues(List<Argument> arguments, ParameterInfo[] parameters)
        {
            var defaultArgs = parameters
                .Skip(arguments.Count)
                .Where(param => param.IsOptional)
                .Select(param => new Argument(Expr.Constant(param.DefaultValue), param.ParameterType));

            arguments.AddRange(defaultArgs);
        }
예제 #7
0
 void DefaultParamTypeValues(List<Argument> arguments, ParameterInfo[] parameters)
 {
     var typeDefaultArgs = parameters
         .Skip(arguments.Count)
         .Select(param => new Argument(Expr.Constant(param.ParameterType.GetDefaultValue()), param.ParameterType));
     arguments.AddRange(typeDefaultArgs);
 }
예제 #8
0
        string HelperGetParams(ParameterInfo[] it)
        {
            var parms = it.Skip(1);
            return String.Join(",", parms.Select(p => HelperFormatType(p.ParameterType) + " " + p.Name));

        }