static private UnreachableCode ( ) : |
||
return |
/// <summary> /// Select matching method from list based on args. /// </summary> /// <param name="targetType"></param> /// <param name="args"></param> /// <param name="methods"></param> /// <param name="methodName"></param> /// <param name="isStatic"></param> /// <returns></returns> private static MethodBase GetMatchingMethodAux(Type targetType, IList <HostArg> args, IList <MethodBase> methods, string methodName, bool isStatic) { int argCount = args.Count; if (methods.Count == 0) { return(null); } if (methods.Count == 1) { return(methods[0]); } IList <DynamicMetaObject> argsPlus = new List <DynamicMetaObject>(argCount + (isStatic ? 0 : 1)); if (!isStatic) { argsPlus.Add(new DynamicMetaObject(Expression.Default(targetType), BindingRestrictions.Empty)); } foreach (HostArg ha in args) { Expr e = ha.ArgExpr; Type argType = e.HasClrType ? (e.ClrType ?? typeof(object)) : typeof(Object); Type t; switch (ha.ParamType) { case HostArg.ParameterType.ByRef: t = typeof(System.Runtime.CompilerServices.StrongBox <>).MakeGenericType(argType); break; case HostArg.ParameterType.Standard: t = argType; break; default: throw Util.UnreachableCode(); } argsPlus.Add(new DynamicMetaObject(Expression.Default(t), BindingRestrictions.Empty)); } // TODO: See if we can get rid of .Default OverloadResolverFactory factory = ClojureContext.Default.SharedOverloadResolverFactory; DefaultOverloadResolver res = factory.CreateOverloadResolver(argsPlus, new CallSignature(argCount), isStatic ? CallTypes.None : CallTypes.ImplicitInstance); BindingTarget bt = res.ResolveOverload(methodName, methods, NarrowingLevel.None, NarrowingLevel.All); if (bt.Success) { return(bt.Overload.ReflectionInfo); } return(null); }