Example #1
0
        public static List <MethodDeclarationSyntax> SearchForMethod(this ClassDeclarationSyntax classDeclaration,
                                                                     MethodMatch methodMatch)
        {
            if (Program.Debug)
            {
                Program.WriteLine(ConsoleColor.Yellow, $"Trying to find {{{UsingDirective.BuildFullMemberTag(methodMatch)}}}");
                Program.IndentLevel++;
            }

            List <MethodDeclarationSyntax> s = Registry.GetMatchedMember(methodMatch);

            if (!Program.SkipOne)
            {
                Program.WriteLine(ConsoleColor.Red, "Skipping for speed");
                s = classDeclaration.Members.OfType <MethodDeclarationSyntax>().Where(methodMatch.Matches)
                    .ToList();
            }

            if (Program.Debug)
            {
                Program.IndentLevel--;
            }

            return(s);
        }
Example #2
0
        /// <summary>
        /// Does this entry match the request
        /// </summary>
        /// <param name="request">The request</param>
        /// <returns>True if it matches</returns>
        public bool IsMatch(HttpRequestHeader request)
        {
            bool ret = true;

            if (request != null)
            {
                if (!PathMatch.IsMatch(request.Path))
                {
                    ret = false;
                }

                if (MethodMatch.IsMatch(request.Method))
                {
                    ret = false;
                }
            }

            return(ret);
        }
Example #3
0
        MethodMatch GetBestMatch(IEnumerable<string> components, string verb)
        {
            string name = components.FirstOrDefault();

            if (name == null)
            {
                MethodMatch match = new MethodMatch();

                if (methods.ContainsKey(verb))
                {
                    match.Method = methods[verb];
                }

                return match;
            }

            IEnumerable<string> remaining = components.Skip(1);

            // prefer direct matches
            if (children.ContainsKey(name))
            {
                var match = children[name].GetBestMatch(remaining, verb);

                if (match != null)
                    match.Score++;

                return match;
            }

            // pick the best dynamic child
            var matches = from entry in children
                          where entry.Value.parameter != null
                          select new { Param = entry.Value.parameter, Match = entry.Value.GetBestMatch(remaining, verb) };

            var bestMatch = matches.Where(m => m.Match != null).OrderByDescending(m => m.Match.Score).FirstOrDefault();

            if (bestMatch != null)
            {
                bestMatch.Match.Params.Add(bestMatch.Param, name);
                return bestMatch.Match;
            }
            else return null;
        }
Example #4
0
        protected TMemberInfo MatchMethod(Type[] args, IEnumerable <TMemberInfo> members)
        {
            LinkedList <MethodMatch> matches = new LinkedList <MethodMatch>();

            foreach (var m in members)
            {
                matches.AddLast(
                    new MethodMatch()
                {
                    method     = m,
                    parameters = Array.ConvertAll <ParameterInfo, Type>(
                        m.GetParameters(),
                        p => p.ParameterType
                        ),
                    weight = 0
                }
                    );
            }


            if (args != null)
            {
                for (int i = 0; i < args.Length; i++)
                {
                    Type t = args[i];
                    for (var node = matches.First; node != null;)
                    {
                        var nextNode = node.Next;
                        if (t != null)
                        {
                            Type paramType = node.Value.parameters[i];
                            if (t.Equals(paramType))
                            {
                                node.Value.weight += 1;
                            }
                            else if (typeof(Delegate).IsAssignableFrom(paramType) && typeof(JsFunction).IsAssignableFrom(t))
                            {
                                // we can assing a js function to a delegate
                            }
                            else if (!m_marshaller.IsAssignable(paramType, t))
                            {
                                matches.Remove(node);
                            }
                        }
                        else
                        {
                            // we can't assign undefined or null values to a value types
                            if (node.Value.parameters[i].IsValueType)
                            {
                                matches.Remove(node);
                            }
                        }
                        node = nextNode;
                    }
                }
            }

            MethodMatch best = null;

            foreach (var match in matches)
            {
                best = best == null ? match : (best.weight < match.weight ? match : best);
            }

            return(best == null ? null : best.method);
        }
Example #5
0
 public int CompareTo(MethodMatch other) => Score.CompareTo(other.Score);
 public DefineDirective(MethodMatch name, MethodDeclarationSyntax realname)
 {
     _name     = name;
     _realname = realname;
 }