Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace DeprecationInCsharp;

[Obsolete("Please use DateUtils instead.")]
public static class LegacyDateUtils
{
public static int GetYear() => 2022;
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
using DeprecationInCsharp;

var deprecatedMethodResult = DateUtils.GetCurrentYearV1();

Check warning on line 3 in csharp-basic-topics/DeprecationInCsharp/DeprecationInCsharp/Program.cs

View workflow job for this annotation

GitHub Actions / Build & test (csharp-basic-topics/DeprecationInCsharp)

'DateUtils.GetCurrentYearV1()' is obsolete: 'Please use GetCurrentYearV2() instead.' (https://example.com/obsoletions/DATEUTILS001)

Check warning on line 3 in csharp-basic-topics/DeprecationInCsharp/DeprecationInCsharp/Program.cs

View workflow job for this annotation

GitHub Actions / Build & test (csharp-basic-topics/DeprecationInCsharp)

'DateUtils.GetCurrentYearV1()' is obsolete: 'Please use GetCurrentYearV2() instead.' (https://example.com/obsoletions/DATEUTILS001)
Console.WriteLine($"Current year from deprecated method: {deprecatedMethodResult}");

var newMethodResult = DateUtils.GetCurrentYearV2();
Console.WriteLine($"Current year from new method: {newMethodResult}");

var legacyYear = LegacyDateUtils.GetYear();

Check warning on line 9 in csharp-basic-topics/DeprecationInCsharp/DeprecationInCsharp/Program.cs

View workflow job for this annotation

GitHub Actions / Build & test (csharp-basic-topics/DeprecationInCsharp)

'LegacyDateUtils' is obsolete: 'Please use DateUtils instead.'

Check warning on line 9 in csharp-basic-topics/DeprecationInCsharp/DeprecationInCsharp/Program.cs

View workflow job for this annotation

GitHub Actions / Build & test (csharp-basic-topics/DeprecationInCsharp)

'LegacyDateUtils' is obsolete: 'Please use DateUtils instead.'
Console.WriteLine($"Year from legacy class: {legacyYear}");
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
10 changes: 5 additions & 5 deletions csharp-basic-topics/DeprecationInCsharp/Tests/Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

Expand All @@ -10,13 +10,13 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.11.0" />
<PackageReference Include="xunit" Version="2.9.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="4.0.1">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.2.0">
<PackageReference Include="coverlet.collector" Version="10.1.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
Loading