3

Possible Duplicate:
ArgumentNullException or NullReferenceException from extension method?

So, I know that extension methods are just syntactic sugar for static helper methods, so you can happily(?) call them on null objects, and won't get a NullReferenceException automatically.

My question is, should you, as a designer of an Extension method, throw a NullReferenceException manually in the extension method - so that it behaves as much as possible like a native method. Or should you do something more conventional and throw an ArgumentNullException?

I guess it's a matter of style, and I'd probably prefer the latter option, but was wondering how far people think you should go when making extension methods look and act like native methods.

Community
  • 1
  • 1
Massif
  • 4,327
  • 23
  • 25
  • ooh... definite duplicate. Didn't turn up when I had a quick look. Glad the answers there chime with my preference. – Massif Mar 01 '11 at 09:12

0 Answers0