コード例 #1
0
        public bool TryBind(MethodInfo methodInfo, Type[] realTypes, out MethodInfo bindedMethod)
        {
            MethodInfo[] candidates;

            bool anyResults =
                TryBind(methodInfo, realTypes, out candidates);

            if (!anyResults)
            {
                bindedMethod = null;
            }
            else
            {
                if (methodInfo.ContainsGenericParameters)
                {
                    IEnumerable <MethodInfo> filtered =
                        candidates.Where(x => x.GetGenericArguments()
                                         .All(y => y != typeof(object)));

                    // Prefer avoiding object as a generic type.
                    if (filtered.Any())
                    {
                        candidates = filtered.ToArray();
                    }
                }

                bindedMethod = (MethodInfo)_methodSelector.Select(candidates, realTypes);
            }

            return(anyResults);
        }
コード例 #2
0
 public MethodBase Select(MethodBase[] candidates, Type[] realTypes)
 {
     try
     {
         return(_child.Select(candidates, realTypes));
     }
     catch (AmbiguousMatchException)
     {
         return(candidates[0]);
     }
 }