4 ms·
Calling IsNullOrWhiteSpace on an instance looks even more counter-intuitive to me, though – it wouldn't work on null if it were a real instance method.
by ptx 12y ago
Calling IsNullOrWhiteSpace on an instance looks even more counter-intuitive to me, though – it wouldn't work on null if it were a real instance method.
- Someone1234 12y agoIt is consistent with how other .Net libraries work (particularly the string ones). It also works fine on null as long as the type of null is string.
- ptx 12y agoIt works because it's an extension method, but aren't extension methods supposed to make things nice and consistent by making it look as if you're calling an instance method? Since this would be completely broken if it were an instance method, the reader might be surprised at first until they realize it's an extension method. So all I'm saying is that it's no less "counter-intuitive" than the normal string.IsNullOrWhiteSpace.
- Arnavion 12y agoIndeed, the fact that extension methods happen to work with `this == null` is more of a bonus feature than something that should be deliberately used.