diff --git a/csharp-basic-topics/DeprecationInCsharp/DeprecationInCsharp/DateUtils.cs b/csharp-basic-topics/DeprecationInCsharp/DeprecationInCsharp/DateUtils.cs index b0adcdcfdd..d1a11e935b 100644 --- a/csharp-basic-topics/DeprecationInCsharp/DeprecationInCsharp/DateUtils.cs +++ b/csharp-basic-topics/DeprecationInCsharp/DeprecationInCsharp/DateUtils.cs @@ -2,7 +2,9 @@ public static class DateUtils { - [Obsolete("Please use GetCurrentYearV2() instead.", false)] + [Obsolete($"Please use {nameof(GetCurrentYearV2)}() instead.", + DiagnosticId = "DATEUTILS001", + UrlFormat = "https://example.com/obsoletions/{0}")] public static int GetCurrentYearV1() { return 2022; diff --git a/csharp-basic-topics/DeprecationInCsharp/DeprecationInCsharp/DeprecationInCsharp.csproj b/csharp-basic-topics/DeprecationInCsharp/DeprecationInCsharp/DeprecationInCsharp.csproj index 2b14c8172d..cd19a35631 100644 --- a/csharp-basic-topics/DeprecationInCsharp/DeprecationInCsharp/DeprecationInCsharp.csproj +++ b/csharp-basic-topics/DeprecationInCsharp/DeprecationInCsharp/DeprecationInCsharp.csproj @@ -2,7 +2,7 @@ Exe - net7.0 + net10.0 enable enable diff --git a/csharp-basic-topics/DeprecationInCsharp/DeprecationInCsharp/LegacyDateUtils.cs b/csharp-basic-topics/DeprecationInCsharp/DeprecationInCsharp/LegacyDateUtils.cs new file mode 100644 index 0000000000..a3b302bfca --- /dev/null +++ b/csharp-basic-topics/DeprecationInCsharp/DeprecationInCsharp/LegacyDateUtils.cs @@ -0,0 +1,7 @@ +namespace DeprecationInCsharp; + +[Obsolete("Please use DateUtils instead.")] +public static class LegacyDateUtils +{ + public static int GetYear() => 2022; +} diff --git a/csharp-basic-topics/DeprecationInCsharp/DeprecationInCsharp/Program.cs b/csharp-basic-topics/DeprecationInCsharp/DeprecationInCsharp/Program.cs index 6c5c9387ef..ab93eff6cf 100644 --- a/csharp-basic-topics/DeprecationInCsharp/DeprecationInCsharp/Program.cs +++ b/csharp-basic-topics/DeprecationInCsharp/DeprecationInCsharp/Program.cs @@ -5,3 +5,6 @@ var newMethodResult = DateUtils.GetCurrentYearV2(); Console.WriteLine($"Current year from new method: {newMethodResult}"); + +var legacyYear = LegacyDateUtils.GetYear(); +Console.WriteLine($"Year from legacy class: {legacyYear}"); diff --git a/csharp-basic-topics/DeprecationInCsharp/Tests/DateUtilsTests.cs b/csharp-basic-topics/DeprecationInCsharp/Tests/DateUtilsTests.cs index 9f04301c9d..5832b8e8c8 100644 --- a/csharp-basic-topics/DeprecationInCsharp/Tests/DateUtilsTests.cs +++ b/csharp-basic-topics/DeprecationInCsharp/Tests/DateUtilsTests.cs @@ -7,7 +7,9 @@ public class DateUtilsTests [Fact] public void WhenUsingV1Method_ThenReturns2022() { +#pragma warning disable DATEUTILS001 var result = DateUtils.GetCurrentYearV1(); +#pragma warning restore DATEUTILS001 Assert.Equal(2022, result); } diff --git a/csharp-basic-topics/DeprecationInCsharp/Tests/Tests.csproj b/csharp-basic-topics/DeprecationInCsharp/Tests/Tests.csproj index 6458a52579..4ed08a7483 100644 --- a/csharp-basic-topics/DeprecationInCsharp/Tests/Tests.csproj +++ b/csharp-basic-topics/DeprecationInCsharp/Tests/Tests.csproj @@ -1,7 +1,7 @@ - net7.0 + net10.0 enable enable @@ -10,13 +10,13 @@ - - - + + + runtime; build; native; contentfiles; analyzers; buildtransitive all - + runtime; build; native; contentfiles; analyzers; buildtransitive all