private static bool DynamicInvokeShuntInternal(object target, MethodShuntKey key, object[] parameters, out object returnValue) { var pairs = from pi in key.Method.GetParameters() join pv in parameters.Select((pv, index) => new { Value = pv, Index = index }) on pi.Position equals pv.Index select new { Parameter = pi, Value = pv.Value } into pair orderby pair.Parameter.Position select pair; bool success = pairs.All(pair => pair.Parameter.ParameterType.IsAssignableFromValue(pair.Value) ); if (success) { returnValue = key.Method.Invoke(target, parameters); return(true); } else { returnValue = null; return(false); } }
public static MethodShuntKey Register(MethodShuntSource source, MethodInfo method) { if (source == null) { throw new ArgumentNullException(nameof(source)); } if (method == null) { throw new ArgumentNullException(nameof(method)); } var key = new MethodShuntKey(source, method); MethodShunt.shuntDic[source].Add(key); return(key); }