【问题标题】:ObsoleteAttribute confusion [duplicate]ObsoleteAttribute 混淆[重复]
【发布时间】:2010-10-12 17:26:32
【问题描述】:

可能重复:
Why are C# collection-properties not flagged as obsolete when calling properties on them?

我想将 ObsoleteAttribute 应用于属性,但编译器似乎只为直接使用属性生成警告/错误,任何间接使用都会被默默忽略。

我认为下面的例子很好地说明了这个问题:

using System;
class Program
{
    static void Main(string[] args)
    {
        var o = new Old();
        Console.WriteLine(o.Geezer); // compilation fails: 'ObsoleteAttributeTest.Program.Old.Geezer' is obsolete: 'Some error' 
        Console.WriteLine(o.Geezer.Attributes); // compiles OK
    }

    class Old
    {
        [ObsoleteAttribute("Some error", true)]
        public System.Xml.XmlElement Geezer { get { return null; } }
    }
}

【问题讨论】:

标签: c# properties attributes obsolete


【解决方案1】:

我相信这是最新 C# 编译器 (C# 3.0) 中的一个已知错误。有another question on StackOverflow与此问题相关。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-12-16
    • 1970-01-01
    • 1970-01-01
    • 2011-08-22
    • 2013-01-29
    • 2018-10-22
    • 2013-01-01
    相关资源
    最近更新 更多