Tag: 属性为

C#:如何实现和使用NotNull和CanBeNull属性

我想让程序员和我自己知道一个方法不需要null ,如果你真的发送null ,结果将不会很漂亮。 在Lokad.Quality命名空间中的Lokad共享库中有一个NotNullAttribute和一个CanBeNullAttribute 。 但是,这是如何工作的? 我查看了这两个属性的源代码,看起来像这样: [AttributeUsage(AttributeTargets.Method | AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.Delegate | AttributeTargets.Field, AllowMultiple = false, Inherited = true)] [NoCodeCoverage] public sealed class NotNullAttribute : Attribute { } [AttributeUsage(AttributeTargets.Method | AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.Delegate | AttributeTargets.Field, AllowMultiple = false, Inherited = true)] [NoCodeCoverage] public sealed class CanBeNullAttribute : Attribute { } […]