Is extending String class with IsNullOrEmpty confusing?

后端 未结 12 1993
有刺的猬
有刺的猬 2020-12-06 01:40

Everyone knows and love String.IsNullOrEmpty(yourString) method.

I was wondering if it\'s going to confuse developers or make code better if we extend String class t

12条回答
  •  南方客
    南方客 (楼主)
    2020-12-06 02:36

    In general, I'm only ok with extension methods being safe to call on null if they have the word 'null' or something like that in their name. That way, I'm clued in to the fact that they may be safe to call with null. Also, they better document that fact in their XML comment header so I get that info when I mouse-over the call.

提交回复
热议问题