本文整理汇总了C#中System.ObsoleteAttribute类的典型用法代码示例。如果您正苦于以下问题:C# ObsoleteAttribute类的具体用法?C# ObsoleteAttribute怎么用?C# ObsoleteAttribute使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ObsoleteAttribute类属于System命名空间,在下文中一共展示了ObsoleteAttribute类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CallOldMethod
//引入命名空间
using System;
using System.Reflection;
public class Example
{
// 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.";
}
public static void Main()
{
Console.WriteLine(OldProperty);
Console.WriteLine();
Console.WriteLine(CallOldMethod());
}
}
输出:
Example.cs(31,25): error CS0619: 'Example.CallOldMethod()' is obsolete: 'This method is obsolete. Call CallNewMethod instead.' Example.cs(29,25): warning CS0618: 'Example.OldProperty' is obsolete: 'This property is obsolete. Use NewProperty instead.'