Q:

Extracting Data from Expression>

Im having a little trouble about extracting some data from Expression<Func<,>>, and having more trouble explaining what i want.
So i have a rest API and im building a method that could work as WFC.
meaning that i will not be needing to call the rest api by url but. 
Building an interface or some kind of wrapper and from that interface we could extract the rest api controller Name, method and parameters.
Ok let me show you how i have imagine it to work.

This is my controller interface

[Route(url: "api/")]
public interface IYoutubeController
{
    /// <summary>
    /// Get a collection of the searched youtube videos
    /// </summary>
    /// <param name="searchString"></param>
    /// <param name="pageSize"></param>
    /// <param name="relatedTo"></param>
    /// <param name="videoSearchType"></param>
    /// <returns></returns>
    [Route]
    YoutubeVideoCollection Search(string searchString, int pageSize = 50, string relatedTo = null, VideoSearchType videoSearchType = VideoSearchType.Videos);

    /// <summary>
    /// Get the playlist video contents
    /// </summary>
    /// <param name="playListId"></param>
    /// <returns></returns>
    [Route]
    List<YoutubeItem> Playlist(string playlistId);

    /// <summary>
    /// decrypted youtube video
    /// </summary>
    /// <param name="videoId"></param>
    /// <returns></returns>
    [Route(httpMethod: HttpMethod.POST)]
    Task<YoutubeVideoInfo> GetVideoAsync(string videoId);
}

This the controller Repository

public static class ControllerRepository
{
    public static async Task<P> Execute<P>(Expression<Func<IYoutubeController, P>> func)
    {
        return await HttpHelper.ExecuteAsync(func);
    }
}

Now i could simple call my method like this 
 YoutubeVideoCollection test = await ControllerRepository.Execute(x => x.Search("Eminem"));

You can se that there is no method seach exist, its only a method in interface.
And here is a httphelper, in it exist PostAsync and GetAsync and also ExecuteAsync
 private static string baseUrl = "http://xxx"
 public static async Task<P> ExecuteAsync<T, P>(Expression<Func<IYoutubeController, P>> func) 
    {
        var url= typeof(T).GetCustomAttribute<Route>()?.Url ?? ""; // eg api/
        var controller = typeof(T).Name; // eg IYoutubeContrller, will be renamed to youtube later on
        var method = // get the method from func P which is Search
        var parameters = // the parameter data from func which is Eminem
        var fullUrl= $"{baseUrl}/{url}/{controller}" 
        // and here we do PostAsync<P>(fullUrl, parameters ) Or GetAsync<P>(fullUrl, parameters )
    }

In HttpHelper ExecuteAsync i want to retrive from my Func<T, P> the Method name which is Search and the parameter which is searchString and also the value of the parameter which is Eminem
Could you help me retrive these information from func parameter?
This is still an idee, so it may not really work, just let me know if its possible.

A:

For your very special case:
Execute(x => x.Search("Eminem"));

You could do this
public static async Task<P> ExecuteAsync<T, P>(Expression<Func<IYoutubeController, P>> func)
{    
    MethodCallExpression callExpression = expression.Body as MethodCallExpression;
    string methodName = callExpression.Method.Name;
    object argument = ((ConstantExpression)callExpression.Arguments).Value;
    // do something
}

But of course this will crash if the expression passed to Execute is more complicated or uses calls with no arguments or non-constant expression arguments etc.
But in that case, you wouldn't know which information to extract at all.

