DeprecatedAttribute vs. ObsoleteAttribute
定义比较
ObsoleteAttribute
[SerializableAttribute]
[AttributeUsageAttribute(AttributeTargets.Class
| AttributeTargets.Struct
| AttributeTargets.Enum
| AttributeTargets.Constructor
| AttributeTargets.Method
| AttributeTargets.Property
| AttributeTargets.Field
| AttributeTargets.Event
| AttributeTargets.Interface
| AttributeTargets.Delegate,
Inherited = false)]
[ComVisibleAttribute(true)]
public sealed class ObsoleteAttribute : Attribute
ObsoleteAttribute is applicable to all program elements except assemblies, modules, parameters, and return values. Marking an element as obsolete informs users that the element will be removed in future versions of the product.
The ObsoleteAttribute class includes two properties:
Message. The string assigned to the Message property is emitted by the compiler when the attribute target is used in code. The string should note that the attribute target is obsolete and, if possible, provide some workaround or programmatic alternative.
IsError. This is a Boolean value that indicates to the compiler whether using the ObsoleteAttribute attribute should cause it to emit an error (IsError is true) or a warning (IsError is false).
For more information about using attributes, see Extending Metadata Using Attributes.
DeprecatedAttribute
public sealed class DeprecatedAttribute : Attribute
字面比较
Deprecated: Express disapproval of.
Obsolete: No longer produced or used; out of date.
关于HTML中的这两个类比是有人这样解释的
It is recommended that you don't use deprecated elements, because they will likely not be supported in the future, whereas obsolete elements have already been discontinued from use.
MSDN解释
Directly applying the Windows.Foundation.Metadata.DeprecatedAttribute attribute to managed code is not recommended, because this export occurs automatically.
When you create a Windows Metadata library (.winmd file), the ObsoleteAttribute is exported as both the ObsoleteAttribute attribute and theWindows.Foundation.Metadata.DeprecatedAttribute attribute if only the ObsoleteAttribute is present in source code. The ObsoleteAttribute is transformed to the DeprecatedAttribute as follows:
If the message and error arguments are both present, message is assigned to the DeprecatedAttributemessage argument. An error value oftrue maps to DeprecationType.Remove, and an error value of false maps to DeprecationType.Deprecate.
If the message argument is not supplied in the ObsoleteAttribute, its default value in the DeprecatedAttribute is "element_name is deprecated", where element_name is the name of the target program element to which the attribute is applied.
If the error argument is not present in the ObsoleteAttribute, its default value in the DeprecatedAttribute is DeprecationType.Deprecate.
个人理解
不同点:
他们属于不同的Framework:(DeprecatedAttribute 命名空间 是Windows.Foundation.Metadata而
ObsoleteAttribute的命名空间是System)
DeprecatedAttribute 是在window8.x 后才开始支持的。
ObsoleteAttribute在.netfraemwork 1.1中引入
参考
DeprecatedAttribute vs. ObsoleteAttribute的更多相关文章
- ObsoleteAttribute 可适用于除程序集、模块、参数或返回值以外的所有程序元素。 将元素标记为过时可以通知用户:该元素在产品的未来版本中将被移除。
官方文档:https://msdn.microsoft.com/zh-cn/library/system.obsoleteattribute(v=vs.110).aspx 备注 ObsoleteAtt ...
- [No00009E]几种常见的命名规则
变量命名规则 必须遵循的命名规则 1. 变量名首字母必须为字母(a-z A-Z),下划线(_),或者美元符号($)开始php编程中所有变量必须以$开始. 2. 变量名只能是字母(a-z A ...
- C#中的 特性 详解(转载)
本篇幅转载于:http://www.cnblogs.com/rohelm/archive/2012/04/19/2456088.html C#中特性详解 特性提供了功能强大的方法,用于将元数据或声明信 ...
- [ASP.NET MVC 小牛之路]02 - C#知识点提要
本人博客已转移至:http://www.exblr.com/liam 本篇博文主要对asp.net mvc开发需要撑握的C#语言知识点进行简单回顾,尤其是C# 3.0才有的一些C#语言特性.对于正在 ...
- Top 15 不起眼却有大作用的 .NET功能集
目录 1. ObsoleteAttribute2. 设置默认值属性: DefaultValueAttribute3. DebuggerBrowsableAttribute4. ??运算符5. Curr ...
- .Net 中的反射(反射特性) - Part.3
反射特性(Attribute) 可能很多人还不了解特性,所以我们先了解一下什么是特性.想想看如果有一个消息系统,它存在这样一个方法,用来将一则短消息发送给某人: // title: 标题:author ...
- C#回顾 –6.特性
1.特性是什么? Attribute 用来对类.属性.方法等标注额外的信息,贴一个标签(附着物) 通俗:给 类 或 类成员 贴一个标签,就像航空部为你的行李贴一个标签一样 个人理解,特性就是修饰 ...
- 利用反射+AOP,封装Basehandler
AOP为Aspect Oriented Programming的缩写,意为:面向切面编程,通过预编译方式和运行期动态代理实现程序功能的统一维护的一种技术.AOP是OOP的延续,是软件开发中的一个热点, ...
- .Net内置特性Attribute介绍
特性Attribute概述 特性(Attribute)是一种特殊的类型,可以加载到程序集或者程序集的类型上,这些类型包括模块.类.接口.结构.构造函数.方法.字段等,加载了特性的类型称之为特性的目标. ...
随机推荐
- MVC 验证码实现( 简易版)
现在网站上越来越多的验证码,使用场景也是越来越多,登陆.注册.上传.下载...等等地方,都有可能大量使用到验证码,那么制作验证码到底有多简单呢?我们一起来看下最简易版的验证码实现过程- 验证码的基本步 ...
- 一行代码引入 ViewPager 无限循环 + 页码显示
(出处:http://www.cnblogs.com/linguanh) 前序: 网上的这类 ViewPager 很多,但是很多都不够好,体现在 bug多.对少页面不支持,例如1~2张图片.功能整合不 ...
- 【NLP】基于机器学习角度谈谈CRF(三)
基于机器学习角度谈谈CRF 作者:白宁超 2016年8月3日08:39:14 [摘要]:条件随机场用于序列标注,数据分割等自然语言处理中,表现出很好的效果.在中文分词.中文人名识别和歧义消解等任务中都 ...
- 你真的会玩SQL吗?玩爆你的数据报表之存储过程编写(上)
你真的会玩SQL吗?系列目录 你真的会玩SQL吗?之逻辑查询处理阶段 你真的会玩SQL吗?和平大使 内连接.外连接 你真的会玩SQL吗?三范式.数据完整性 你真的会玩SQL吗?查询指定节点及其所有父节 ...
- php内核分析(七)-扩展
这里阅读的php版本为PHP-7.1.0 RC3,阅读代码的平台为linux. 我们研究下反射这个扩展. 反射这个扩展目录是存在在:ext/reflection.其实里面的代码很简单.一个.h文件,一 ...
- request 对象和 response 对象
Web服务器收到客户端的http请求,会针对每一次请求,分别创建一个用于代表请求的request对象.和代表响应的response对象 HttpServletResponse HttpServletR ...
- C# 系统托盘图标
C# 系统托盘图标 WPF NotifyIcon 资料 网址: http://www.codeproject.com/Articles/36468/WPF-NotifyIcon http://www. ...
- 03 通过Button打开另一个的frm
private void Form1_FormClosing(object sender, FormClosingEventArgs e) { DialogResult re = MessageBox ...
- 【转】MVC、MVP与MVT
MVC是Model-View-Control的缩写,Model指的是数据层,View指的是UI层,Control指的是控制层,这三层之间彼此联系.View层的用户行为,触发Control层,Contr ...
- Effective java笔记(一),创建与销毁对象
1.考虑用静态工厂方法代替构造器 类的一个实例,通常使用类的公有的构造方法获取.也可以为类提供一个公有的静态工厂方法(不是设计模式中的工厂模式)来返回类的一个实例.例如: //将boolean类型转换 ...