Insufficient entity

Possible duplicate:
Why are the properties of the C # collection not marked obsolete when properties are called on them?

I would like to apply ObsoleteAttribute to the property, but it seems that the compiler generates warnings / errors only for direct use of the attribute, any indirect use is 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; } }
    }
}
+3
source share
2 answers

I believe this is a known bug in the latest C # compiler (C # 3.0). There is fooobar.com/questions/388600 / ... related to this problem.

+1
source

var o = new Old(); . CS0246: "var" ( using ?) Old o = new Old(); , CS0619: "Program.Old.Geezer" : " " , , ..!!!!!!!!!!

0

Source: https://habr.com/ru/post/1704593/


All Articles