.NET ObsoleteAttribute
2015-09-11 22:00
357 查看
对于有不同版本的程序代码,obsoleteattribute显得大有用武之地。如果开发了一个新的方法,并且可以确定不再希望使用某方法,那么就可以使用Obsoleteattribute来修饰该方法,编译代码后,按警告/错误提示信息逐一更正原来的代码。在一个大型工程中,有助于协调不同的程序员所采用的方法。
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace CSharpAttribute { class Program { // Mark OldProperty As Obsolete. [ObsoleteAttribute("This property is obsolete. Use NewProperty instead.", false)] public static string OldProperty { get { return "The old property value."; } } public static string NewProperty { get { return "The new property value."; } } // Mark CallOldMethod As Obsolete. [ObsoleteAttribute("This method is obsolete. Call CallNewMethod instead.", true)] public static string CallOldMethod() { return "You have called CallOldMethod."; } public static string CallNewMethod() { return "You have called CallNewMethod."; } static void Main(string[] args) { Console.WriteLine(OldProperty); Console.WriteLine(NewProperty); Console.WriteLine(); //Console.WriteLine(CallOldMethod()); Console.WriteLine(CallNewMethod()); Console.ReadKey(); } } }结果:
The old property value. The new property value. You have called CallNewMethod.调用过时方法是无法通过编译的:
相关文章推荐
- android---2048游戏实现
- CF 500 B. New Year Permutation 并查集
- GraphViz的dot绘图
- 学英语
- 第二章 数据类型
- ACM学习历程—HDU 3092 Least common multiple(数论 && 动态规划 && 大数)
- 关于try{} catch(exception e )
- ios-UIDynamicAnimator(物理仿真动画)
- Java垃圾回收_过程观察
- Anroid View事件响应机制和ViewGroup的事件响应分发机制
- Scala 深入浅出实战经典 第90讲:基于Scala的Actor之上的分布式并发消息驱动框架Akka初体验
- BMfont生成NGUI自定义中文字体
- java5
- Web开发设计(二)
- 我的Android开源项目:JNote
- 使用gcc编译windows程序
- [cocos2dx]利用NDK崩溃日志查找BUG
- Java 可变参数
- SAM习题集合
- Codeforces 282C XOR and OR