NOTNULL属性 [英] NotNull attribute

查看:136
本文介绍了NOTNULL属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我期待在asp.net vnext 工程指导并已经注意到,他们建议使用 NOTNULL 属性,而不是对空和投掷 ArgumentNullException 输入参数明确的检查。这让我感到困惑的事情是本准则的基础是刚够声明这个属性和检查代码在编译时将进入方法体生成。我试图做到这一点在我的测试项目,不过魔术没有发生即它抛出异常 System.NullReferenceException 而不是 System.ArgumentNullException的。这是如何工作的? ?他们要使用一些AOP库在编译时注入检查代码

I'm looking at asp.net vnext engineering guideline and have noticed that they recommend to use NotNull attribute instead of explicit checking of input argument for null and throwing ArgumentNullException. The thing that confused me is that base on this guideline it is just enough to declare this attribute and the checking code will be generated at compile time into the method body. I've tried to do this in my test project however the magic didn't happen i.e. it threw the exception System.NullReferenceException instead of System.ArgumentNullException. How this is supposed to work? Are they going to use some AOP library to inject the checking code at compile time?

推荐答案

更新时间:2016年1月12日

Updated: Jan 12, 2016

NotNullAttribute 不见了。我们删除它,目前也没有计划把它带回来。

The NotNullAttribute is gone. We removed it and currently there's no plan to bring it back.

<击>属性将通过一个预编译取代步骤,使用罗斯林,通过代码进行实际检查。

The attribute will be replaced through a precompilation step, using Roslyn, by code that does the actual check.

不过,该功能还没有准备好。它会在以后的版本。

However, the feature is not yet ready. It will come in a later version.

这篇关于NOTNULL属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆