From 6b8d95a3a0054bf99375b0bb3de3d6d92835f1b5 Mon Sep 17 00:00:00 2001 From: Bartosz Klonowski Date: Sat, 10 Aug 2024 22:29:39 +0200 Subject: [PATCH 1/2] Add the section to CS0809 about methods recognized as obsolete --- docs/csharp/misc/cs0809.md | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/docs/csharp/misc/cs0809.md b/docs/csharp/misc/cs0809.md index e2c10d0f872f5..cc5c3d59453da 100644 --- a/docs/csharp/misc/cs0809.md +++ b/docs/csharp/misc/cs0809.md @@ -36,3 +36,32 @@ public class C : Base } } ``` + +## Methods recognized as obsolete + +Note that the compiler warning `CS0809` will lead to no [`CS0618`](../language-reference/compiler-messages/cs0618.md) warning when actually calling the obsolete method. +
In the following example compiler will not warn about the method `Test` being obsolete, because the declaration that is recognized by compiler when calling is in the base class `Base`, not the derived class `Derived`: + +```csharp +class Base +{ + public virtual void Test() {} +} + +class Derived : Base +{ + [System.Obsolete()] + public override void Test() { } +} + +static class Program +{ + public static void Main() + { + Derived derived = new(); + b.Foo(); // No CS0618 + } +} +``` + +To fix this add the `Obsolete` attribute to base class as well. From e4851058854fafabca55d998a37365a38211ed57 Mon Sep 17 00:00:00 2001 From: Bartosz Klonowski Date: Sat, 10 Aug 2024 22:33:37 +0200 Subject: [PATCH 2/2] Add the 'See also' section to link other, related, warnings --- docs/csharp/misc/cs0809.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/csharp/misc/cs0809.md b/docs/csharp/misc/cs0809.md index cc5c3d59453da..4d2530bcb074f 100644 --- a/docs/csharp/misc/cs0809.md +++ b/docs/csharp/misc/cs0809.md @@ -65,3 +65,8 @@ static class Program ``` To fix this add the `Obsolete` attribute to base class as well. + +## See also + +- [CS0618](../language-reference/compiler-messages/cs0618.md) +- [CS0672](./cs0672.md)