BUY Cardura ONLINE WITHOUT PRESCRIPTION

August 4th, 2008

BUY Cardura ONLINE WITHOUT PRESCRIPTION, OK, I'm ashamed this extension method took me this long to think of.  It is the first extension method that I've created that warrants extending Object as well.  But the fact that it doesn't exist makes me think there might be a reason for that as well (shrugs).

   1: public static T CastOrDefault<T>(this System.Object o)
   2: {
   3:     if (o == null) return default(T);
   4:     
   5:     if (o is T)
   6:     {
   7:         return (T) o;
   8:     }
   9:     else
  10:     {
  11:         return default(T);
  12:     }
  13: }

This method is a blood brother to FirstOrDefault.  FirstOrDefault extends IEnumerable to return the first item in the list, or if there is nothing in the list, it returns the default value (often null).

This is CastOrDefault.  It casts an object or returns the default value if it can't.

Uses: in my current application I have to deal with a lot of lists that return base types (Component, object, Control, etc) and I need them more specific.   So I end up writing the same block over and over to check if the object is null, if I can cast it, then cast the object, and return it.  That code is now gone.

Here is a trivial example for when you know the name of object at runtime, but not at design time:

   1: private Label GetLabel(string name)
   2: {
   3:    return this.Controls[name].CastOrDefualt<Label>();
   4: }
. Where can i find Cardura online. Where to buy Cardura. Comprar en línea Cardura, comprar Cardura baratos. Buy Cardura online cod. Where can i buy Cardura online. Rx free Cardura. Purchase Cardura online. Real brand Cardura online. Canada, mexico, india. Buy cheap Cardura no rx. Buy Cardura ONLINE WITHOUT prescription. Where can i buy cheapest Cardura online. Order Cardura online c.o.d. Cardura gel, ointment, cream, pill, spray, continuous-release, extended-release. Purchase Cardura ONLINE WITHOUT prescription. Buying Cardura online over the counter. Ordering Cardura online. Buy cheap Cardura. Australia, uk, us, usa. Japan, craiglist, ebay, overseas, paypal. Buy generic Cardura. Buy Cardura from canada. Cardura over the counter. Fast shipping Cardura. Cardura from canadian pharmacy. Buy Cardura no prescription. Purchase Cardura. Kjøpe Cardura på nett, köpa Cardura online. Where to buy Cardura. Online buying Cardura hcl. Cardura samples. Cardura trusted pharmacy reviews. Cardura for sale. Buy Cardura from mexico. Where can i order Cardura without prescription. Order Cardura from mexican pharmacy. Online buy Cardura without a prescription. Order Cardura from United States pharmacy. Order Cardura no prescription. Order Cardura online overnight delivery no prescription. Buy Cardura without a prescription. Buy no prescription Cardura online. Buy Cardura without prescription. Cardura price, coupon. Buy Cardura from canada.

Similar posts: BUY Metformin ONLINE WITHOUT PRESCRIPTION. BUY Tafil-Xanor ONLINE WITHOUT PRESCRIPTION. Where to buy Hydrea. Fast shipping Lopressor.
Trackbacks from: BUY Cardura ONLINE WITHOUT PRESCRIPTION. BUY Cardura ONLINE WITHOUT PRESCRIPTION. Cardura over the counter. Order Cardura online c.o.d. Where to buy Cardura.

  • Steve

    Except for structs what is different with just using as?

    1: private Label GetLabel(string name)

    2: {

    3: return this.Controls[name] as Label;

    4: }

  • http://www.elegantcode.com Chris Brandsma

    Mainly that it does work with Struts.

    Here is another example. You are loading a TreeView, every tree node has it’s tag set to a number. You catch the AfterSelect event and do this:

    private void BuildingStructureTreeView_AfterSelect(object sender, TreeViewEventArgs e)
    {
    var value = e.Node.Tag.CastOrDefault());
    }

    That said, the “as ” will work for most cases.

  • Pingback: Link Post For August 7 2008 | One .Net Way