Declare an implemented IEnumerable interface or class as deprecated

Is it possible to declare a derived or implemented part of an IEnumerable interface or class as deprecated, while the rest of the class or interface is still relevant? How to declare it?

interface Foo : IEnumerable<Bar>{

    int SomethingNonObsolete{
         get;
    }

}

In the above example, I would like the use of iterators of the implemented IEnumerable to result in an obsolete compiler-warning, while using the interface itself or using SomethingNonObsolete-Property does not result in such a warning.

The following code should result in an outdated compiler warning

foreach(var bar in myFooImplementingInstance){

The following code should not lead to an outdated compiler warning

myFooImplementingInstance.SomethingNonObsolete.ToString()

UPDATE
, , :

, - LINQ.

, Panda , . .

[Obsolete]
IEnumerator<Bar> GetEnumerator()
[Obsolete]
IEnumerator IEnumerable.GetEnumerator()

, . .

[Obsolete]
new IEnumerator<ITabularDataRow> GetEnumerator();

, , , LINQ. , (. MDeSchaepmeester).

+4
4

Obsolete GetEnumerator, , :

public class MyClass : Foo
{
    public int SomethingNonObsolete
    {
        get
        {
            throw new NotImplementedException();
        }
    }

    [Obsolete]
    public IEnumerator<Bar> GetEnumerator()
    {
        throw new NotImplementedException();
    }

    [Obsolete]
    IEnumerator IEnumerable.GetEnumerator()
    {
        throw new NotImplementedException();
    }
}

:

var c = new MyClass();

// Flagged as obsolete
foreach (var blah in c)
{

}

// Not flagged as obsolete
var s = c.SomethingNonObsolete;
+4

ObsoleteAttribute . , ( , ). , , , , Foo. - Foo2 - , .

, . , ((IEnumerable<Bar>)yourFooInstance).GetEnumerator() .

+2

, , , - API.

Obsolete , , , XML- (, SomethingNotObsolete Obsolete use SomethingNew instead).

, API, , . () API .

, , , Obsolete .

0

. IEnumerable Obsolete. whoeever foreach(Foo f in myFooImplementingInstance) . , . , . . , , .

@MDeSchaepmeester, , . , .

0
source

All Articles