简体   繁体   English

当扩展方法中的this参数为null时,我应该抛出什么?

[英]What should I throw when the `this` parameter is null in extension methods?

What should I throw when the this parameter is null in extension methods? 在扩展方法中this参数为null时,我应该抛出什么?

If I should throw ArgumentNullException , what should the name of the parameter be? 如果我应该抛出ArgumentNullException ,那么ArgumentNullException的名称应该是什么?

是的,抛出ArgumentNullException ,并提供参数的名称。

我认为您可以考虑不执行任何操作,因为将发生的是在该参数的扩展主体中引起NullReferenceException的情况,这实际上正是使用扩展方法时语义的外观。

最后,扩展方法只是一种花哨的静态方法,所以我会采用与它们相同的方法

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM