private static PooledList <ParameterPair> GetPairs(UrlTemplate template, IMethodSymbol method)
        {
            var list = PooledList <ParameterPair> .Borrow();

            foreach (var parameter in method.Parameters)
            {
                if (IsFromRoute(parameter))
                {
                    list.Add(template.Path.TrySingle(x => x.Parameter?.Name.Text == parameter.Name, out var templateParameter)
                                 ? new ParameterPair(templateParameter.Parameter, parameter)
                                 : new ParameterPair(null, parameter));
                }
            }

            foreach (var component in template.Path)
            {
                if (component.Parameter is TemplateParameter templateParameter &&
                    list.All(x => x.Template != templateParameter))
                {
                    list.Add(new ParameterPair(templateParameter, null));
                }
            }

            return(list);
        }
        private static PooledList <ParameterPair> GetPairs(UrlTemplate template, IMethodSymbol method)
        {
            var list = PooledList <ParameterPair> .Borrow();

            foreach (var parameter in method.Parameters)
            {
                if (IsFromRoute(parameter))
                {
                    list.Add(template.Path.TrySingle(x => x.Parameter?.Name.Equals(parameter.Name, StringComparison.Ordinal) == true, out var templateParameter)
                                 ? new ParameterPair(templateParameter.Parameter, parameter)
                                 : new ParameterPair(null, parameter));
                }
            }

            foreach (var component in template.Path)
            {
                if (component.Parameter is TemplateParameter templateParameter &&
                    list.All(x => x.Route != templateParameter))
                {
                    list.Add(new ParameterPair(templateParameter, null));
                }
            }

            return(list);

            bool IsFromRoute(IParameterSymbol p)
            {
                foreach (var attributeData in p.GetAttributes())
                {
                    if (attributeData.AttributeClass == KnownSymbol.FromRouteAttribute)
                    {
                        continue;
                    }

                    return(false);
                }

                return(true);
            }
        }
示例#3
0
 /// <summary>
 /// Borrow a list, dispose returns it.
 /// </summary>
 /// <typeparam name="T">The type of keys.</typeparam>
 /// <returns>A <see cref="PooledList{T}"/>.</returns>
 public static PooledList <T> Borrow <T>() => PooledList <T> .Borrow();