3

Possible Duplicate:
Why are C# collection-properties not flagged as obsolete when calling properties on them?

I would like to apply ObsoleteAttribute to a property, but it seems that compiler generates warnings/errors only for direct usage of attribute, any indirect usage is silently ignored.

I think the following example illustrates the problem very well:

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; } }
    }
}
Community
  • 1
  • 1
Ev Dolzhenko
  • 6,100
  • 5
  • 38
  • 30

1 Answers1

1

I believe this is a known bug in the latest C# compiler (C# 3.0). There is another question on StackOverflow relating to this problem.

Community
  • 1
  • 1
Jeff Yates
  • 61,417
  • 20
  • 137
  • 189