So I was wondering if it is possible to check how many lines of code is when given a delegate. So for example lets say I have this method:
private int Foo()
{
var @string = "string";
var count = @string.Count();
}
The program would would return '2' because the method has 2 lines of code. I was thinking about how to do this using reflection, but I am no master with it. So at the moment I have a function that looks like this:
public static string Measure(this Action del)
{
var timer = new Stopwatch();
var length = // Length of the action
timer.Start();
del.Invoke();
timer.Stop();
return timer.Elapsed.TotalMilliseconds.ToString(CultureInfo.CurrentCulture);
}
And called like this:
Benchmark.Measure(() =>
{
var @string = "string";
var count = @string.Count();
});
So in this case length would be '2'
Aucun commentaire:
Enregistrer un commentaire