jeudi 7 décembre 2017

Returning name of the concrete implementation of a func<> delegate

tl;dr version: nameof(ToCelsius) returns ToCelsius. I want something that returns the name of the underlying function, ToCelsiusByA, though.

My ToCelsius is assigned a concrete implementation thus:

 Func<decimal,decimal> ToCelsius = ToCelsiusByA;

I then call the ToCelsius function:

var degreesC = ToCelsius(degreesF);

I'd like to name of the implemented function (ToCelsiusByA) returned, so I'm trying this:

Console.WriteLine(degreesF + " degrees F is " + degreesC + " degrees C! using " + nameof(ToCelsius));

but, of course, this shows 'ToCelsuis' in the string.





Aucun commentaire:

Enregistrer un commentaire