public static bool HasParameterArgument(this MethodCallExpression node, Type type = null) { node.MustNotBeNull(); foreach (var arg in node.Arguments) { if (arg.IsParameter(type) || arg.BelongsToParameter(type)) { return(true); } } return(false); }
/// <summary> /// /// </summary> /// <exception cref="NotSupportedException"></exception> /// <param name="node"></param> /// <returns></returns> public static object GetValue(this MethodCallExpression node) { node.MustNotBeNull(); if (node.Arguments.Any(a => !a.CanReturnValue())) { throw new NotSupportedException("Can't identify the value of at least one argument"); } var args = node.Arguments.Select(a => a.GetValue()).ToArray(); object parent = null; if (node.Object != null && node.Object.CanReturnValue()) { parent = node.Object.GetValue(); } return(node.Method.Invoke(parent, args)); }