News for hackers. Stuff that matters.
Re:C#: No, you don’t get to use the “as” operator any more by InclinedPlane on Friday April 29, 2011 @05:06PM (#2498991)
((e.NewItem as Customer) ?? Customer.NullObject).Save();

Edit: The idea being, you have a sub-class of Customer which implements the Null Object pattern, which you instantiate through a static member on Customer or a Property method or what-have-you. The great thing about this is that you can tailor the behavior in this situation to whatever you want. Want to throw an exception? Sure, throw whatever exception you want from CustomerNullObject.Save(). Want to log an error and otherwise silently fail? No prob, easy peasy.

There are no comments on this comment yet.