samedi 23 décembre 2017

How to log parameters from generic function

Given the following code:

int result = Execute(() => Foo(1, 2));

public int Foo(int x, int y)
{
    return x + y;
}

public T Execute<T>(
    Func<T> function)
{
    Console.Write(function.Method.Name + ": " + string.Join(", ", params));
    return function();
}

Is it possible to get the parameters? So the output would read something like:

"Foo: 1, 2"





Aucun commentaire:

Enregistrer un commentaire