Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ObsoleteAttribute confusion [duplicate]

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; } }
    }
}
like image 701
dolzenko Avatar asked May 19 '26 00:05

dolzenko


1 Answers

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.

like image 156
2 revsJeff Yates Avatar answered May 21 '26 14:05

2 revsJeff Yates



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!