Get Viagra Fast

25Feb/091

Pfizer Soft Viagra

Pfizer soft viagra I've felt the pain of having the using statement not being able to return a value before, pfizer soft viagra and just chalked it up to a limitation of the language.

Pfizer soft viagra I never considered trying to find a better way, pfizer soft viagra and usually ended up with something like:

void DoSomething()
{
    XmlDocument xml = new XmlDocument();
    using(var reader = new StreamReader(@"c:\somexmlfile.xml"))
    {
        xml.Load(reader);
    }

    // do something useful with xml
}

Pfizer soft viagra or

void DoSomething2()
{
    XmlDocument xml = new XmlDocument();
    using( var reader = new StreamReader( @"c:\somexmlfile.xml" ) )
    {
        xml.Load( reader );
        // do something useful with xml
    }
}

Pfizer soft viagra Neither of which particularly suited me. Pfizer soft viagra Because

  • First example: Declaring the variable outside the scope of the block feels weird
  • Second example: Performing whatever operation inside the using block, pfizer soft viagra means the file (or other resource) doesn't get released until the operation has completed.

Pfizer soft viagra After Shawn mentioned something about this at his Indy Alt.Net Clojure talk, pfizer soft viagra I started thinking about it a little bit, pfizer soft viagra and then I had a real need for it (again), pfizer soft viagra and decided to come up with something better.  Turns out what I wanted was blatantly simple.

TResult UsingReturn(TDisposable toUse, pfizer soft viagra Func func)
    where TDisposable : IDisposable
{
    using (toUse)
    {
        return func(toUse);
    }
}

Pfizer soft viagra Now the above example turns into:

void DoSomething3()
{
    var xml = UsingReturn( new StreamReader( @"c:\cdf.xml" ), pfizer soft viagra reader =>
                {
                    var doc = new XmlDocument();
                    doc.Load( reader );
                    return doc;
                });
}

Pfizer soft viagra I'm not sure where this thing should live (e.g. Pfizer soft viagra some static utility class, pfizer soft viagra extension method on IDisposable), pfizer soft viagra or even what it should be called.  Any ideas?

Average Rating: 5 out of 5 based on 226 user reviews.

Comments (1) Trackbacks (0)
  1. Jon, this is good stuff too. Regarding where it should live and what it should be called … here’s an idea. It will be controversial, and truth is, I’m not 100% sold on it myself. But it’s food for thought:

    Some things are so fundamental and likely to be used so commonly that they are almost like extensions to the language itself. Using those things should be easy and they should read “fluently” (in the general sense, not in the specific sense of “method chaining”). Maybe you put this in a static class named with one letter, like “X” for “eXtensions”. This is sort of like how Prototype and now many JavaScript libraries use $.


Leave a comment


No trackbacks yet.