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)是一种特殊的类型,可以加载到程序集或者程序集的类型上,这些类型包括模块.类.接口.结构.构造函数.方法.字段等,加载了特性的类型称之为特性的目标. ...
随机推荐
- Jquery Uploadify3.21.与2.1版本 使用中存在的问题--记录三
Jquery Uploadify是个上传插件. 2.1版本与3.2.1版本有很大区别,方法名跟参数变动较大 1.uploader:该属性是用来存放swf的路径,这个swf就是一个Flash的一个图标, ...
- Ninesky源代码从Codeplex迁移到开源中国
原来Ninesky代码一直发在Codeplex.com上,最近两三个星期了代码一直迁入不上去,网站访问也经常出错. 所以把代码放到开源中国去了,项目地址https://git.oschina.net/ ...
- ubuntu14.04安装及web环境的搭建
在进行接下来的工作之前首先得准备一个Ubuntu的启动U盘以及腾出一个至少50G的系统盘(在网上看到有人用20G的,不知道效果怎么样).关于Ubuntu启动U盘大家可以参考这个帖子 http://ti ...
- YYModel 源码解读(二)之NSObject+YYModel.h (4)
接下来我们继续向下看 typedef struct { void *modelMeta; ///< _YYModelMeta void *model; ///< id (self) voi ...
- 用 jQuery.ajaxSetup 实现对请求和响应数据的过滤
不知道同学们在做项目的过程中有没有相同的经历呢?在使用 ajax 的时候,需要对请求参数和响应数据进行过滤处理,比如你们觉得就让请求参数和响应信息就这么赤裸裸的在互联网里来回的穿梭,比如这样: 要知道 ...
- 使用webfont为easyui扩充图标
目前回到pc端开发,开始用了easyui这个框架.重拾easyui后感觉这个框架用的很多技术太古老,页面风格也太控件化.单从图标一项来说吧,这种花花绿绿的图标用户一看都傻了眼,同时整个框架就提供了那么 ...
- Linux 系统命令笔记
前言 翻出N年前学习笔记,感觉还有点用,放到博客备忘,自己查看用. 一. 系统命令笔记 1.系统 % /etc/issue # 查看操作系统版本 % # 观察系 ...
- FFmpeg学习2:解码数据结构及函数总结
在上一篇文章中,对FFmpeg的视频解码过程做了一个总结.由于才接触FFmpeg,还是挺陌生的,这里就解码过程再做一个总结. 本文的总结分为以下两个部分: 数据读取,主要关注在解码过程中所用到的FFm ...
- C# - 计时器Timer
System.Timers.Timer 服务器计时器,允许指定在应用程序中引发事件的重复时间间隔. using System.Timers: // 在应用程序中生成定期事件 public class ...
- Guid的使用
今天在公司做修改功能时,老大让使用部分更新,但是表中的主键是UNIQUEIDENTIFIER类型,它会在我们添加纪录时,默认生成一个unicode码, 但是我现在必须要将获取到的已经是string类型 ...