/// <summary> /// Extract values of <see cref="ConstantExpression"/> /// </summary> /// <param name="at">The <see cref="LambdaExpression"/> from which to extract <see cref="ConstantExpression.Value"/>'s</param> /// <returns>Extracted values</returns> public static object[] Locate(LambdaExpression at) { var @this = new ConstantExpressionValuesLocator(); @this.Visit(at); return(@this.values.ToArray()); }
/// <summary> /// Creates an <see cref="IInvocationInfo"/> instance from the target <paramref name="expression"/>. /// </summary> /// <param name="expression">The <see cref="LambdaExpression"/> from which to create an <see cref="IInvocationInfo"/> instance.</param> /// <returns><see cref="IInvocationInfo"/>.</returns> public static IInvocationInfo ToInvocationInfo(this LambdaExpression expression) { var simplified = expression.Simplify(); switch (simplified?.Body) { case MethodCallExpression methodCallExpresssion: return(new MethodInvocationInfo(methodCallExpresssion.Method, ConstantExpressionValuesLocator.Locate(simplified))); case MemberExpression memberExpression: return(new MemberInvocationInfo(memberExpression.Member)); } throw new NotSupportedException($"Expression type ({simplified?.Body.NodeType}) not supported."); }