c# - 具有属性的快速 ArgumentNullException。有可能的?

标签 c# attributes methods

有没有快速验证空参数的方法 通过属性或其他什么?

转换这个:

public void Method(type arg1,type arg2,type arg3)
{
     if (arg1== null) throw new ArgumentNullException("arg1");
     if (arg2== null) throw new ArgumentNullException("arg2");
     if (arg3== null) throw new ArgumentNullException("arg3");
     //Business Logic
}

像这样:

[VerifyNullArgument("arg1","arg2","arg3")]
public void Method(type arg1,type arg2,type arg3)
{
      //Business Logic
}

想法?谢谢大家。

最佳答案

Code Contracts内置于 .NET 4 中。这可能与您所获得的一样接近。在 DevLabs 上有更多信息。如果你选择走这条路。

关于c# - 具有属性的快速 ArgumentNullException。有可能的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2846487/

相关文章:

c# - 回发后滚动到面板 C#

c# - 类似sql的查询不起作用

opengl - GLSL 1.5 和 OpenGL 3.3 : Passing color to vertex shader seems to fail

java - 查找字符串的字典序号的方法

java - 为什么列表不能包含在 `Integer...` 参数中

c# - 一些我似乎无法理解的共享点概念

objective-c - 我们什么时候应该在 Objective-C 方法中使用 "__attribute__((unused))"?

javascript - 如何在 jQuery 中获取下一个或上一个属性 ID?

python - 如何在Python中将方法作为属性调用?

java - C#数组[,]转Java,具体数组的概念