Reputation: 5063
What should I throw when the this
parameter is null in extension methods?
If I should throw ArgumentNullException
, what should the name of the parameter be?
Upvotes: 1
Views: 82
Reputation: 8303
In the end extension methods are kind of just fancy static methods so I'd take the same approach you would with them
Upvotes: 1
Reputation: 40160
I think you could consider doing nothing about it, because what will happen is a NullReferenceException will be caused in the extension body for that parameter, which is actually exactly what the semantics appear like on the usage of the extension method.
Upvotes: 2
Reputation: 80840
Yes, throw an ArgumentNullException
, and provide whatever the name of your parameter really is.
Upvotes: 4