private object CallMethodInternal(string name, ICollection <Type> argTypes, ParameterModifier[] argModifiers, object[] argValues) { if (argTypes == null) { throw new ArgumentNullException("argTypes"); } if (argValues == null || argValues.Length == 0) { argValues = argTypes.Select(t => MockingUtil.GetDefaultValue(t)).ToArray(); } if (argTypes.Count != argValues.Length) { throw new ArgumentException("The number of argument types does not match the number of argument values"); } var argValueIndex = 0; foreach (var argType in argTypes) { if (argValues[argValueIndex] != null && argType != argValues[argValueIndex].GetType() || argValues[argValueIndex] == null && argValues[argValueIndex] != MockingUtil.GetDefaultValue(argType)) { throw new ArgumentException("One or more arguments types does not match the argument values"); } argValueIndex++; } var candidates = type.GetAllMethods() .Where(m => m.Name == name && MockingUtil.CanCall(m, this.instance != null)) .Select(m => MockingUtil.TrySpecializeGenericMethod(m, argTypes.ToArray()) ?? m) .ToArray(); var method = MockingUtil.SelectMethod(MockingUtil.AllMembers, candidates, argTypes.ToArray(), argModifiers); return(CallInvoke(method, argValues)); }