mishrsud / mvc-mini-profiler

Automatically exported from code.google.com/p/mvc-mini-profiler
0 stars 0 forks source link

Add MiniProfilerExtensions.Step that takes an Action. #1

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
I added the following method to MiniProfilerExtensions and thought it might be 
useful for others:

    public static TResult Step<TResult>(this MiniProfiler profiler, string name, Func<TResult> func)
    {
        using (profiler == null ? null : profiler.StepImpl(name))
        {
            return func();
        }
    }

This way you can time a section of code that returns a value. For example:

    MiniProfiler p = ...;

    // use linq to return an anonymous type
    var results = p.Step("Query", ()=> (from v in values select new {v.A, v.B}).ToArray());

    // or call a method: TResult DoSomething() {}
    var somethingResult = p.Step("Do Something", DoSomething);

Original issue reported on code.google.com by mbe...@gmail.com on 3 May 2011 at 3:50

GoogleCodeExporter commented 8 years ago
Is this issue still relevant as there is the extention method called Inline 
with the signature: 
public static T Inline<T>(this MiniProfiler profiler, Func<T> selector, string 
name)
This seems to achieve the same result just with a different method name and 
parameter order.

I can also see the merit in having an overloaded method so the developer just 
needs to use the Step extension method.

Original comment by MHB...@gmail.com on 14 Jul 2011 at 8:51

GoogleCodeExporter commented 8 years ago
The Inline extension method are useful lines of code which returns a value. But 
the Inline method cannot be used to profile code which doesn't return a value. 
To enable this scenario a overload which takes an action should exists.

I also think the Inline method should be made Obsolete, and create the Step 
extension method suggested above instead.

Original comment by kimwork...@gmail.com on 25 Jul 2011 at 12:11

GoogleCodeExporter commented 8 years ago
I've created a clone and implemented my suggested changes above. The clone can 
be found here http://code.google.com/r/kimworking-steps-selector-lambda/

Original comment by kimwork...@gmail.com on 25 Jul 2011 at 12:39

GoogleCodeExporter commented 8 years ago
declining this for now, nothing stopping end users adding whatever extension 
methods they need, but do not want to complicate the external API with too many 
options

Original comment by sam.saff...@gmail.com on 15 Aug 2011 at 12:45