Skip to content

Commit 72c3c66

Browse files
authored
Allow use of C# 13
1 parent 1726b52 commit 72c3c66

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

Directory.Build.props

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project>
22
<PropertyGroup>
3-
<LangVersion>12</LangVersion>
3+
<LangVersion>13</LangVersion>
44
<Nullable>enable</Nullable>
55
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
66
<AnalysisLevel>8.0-all</AnalysisLevel>

MoreLinq/Experimental/Memoize.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public static IEnumerable<T> Memoize<T>(this IEnumerable<T> source) =>
6565
sealed class MemoizedEnumerable<T>(IEnumerable<T> sequence) : IEnumerable<T>, IDisposable
6666
{
6767
List<T>? cache;
68-
readonly object locker = new();
68+
readonly Lock locker = new();
6969
readonly IEnumerable<T> source = sequence ?? throw new ArgumentNullException(nameof(sequence));
7070
IEnumerator<T>? sourceEnumerator;
7171
int? errorIndex;
@@ -77,7 +77,9 @@ public IEnumerator<T> GetEnumerator()
7777
{
7878
lock (this.locker)
7979
{
80+
#pragma warning disable CA1508 // Avoid dead conditional code
8081
if (this.cache == null)
82+
#pragma warning restore CA1508 // Avoid dead conditional code
8183
{
8284
this.error?.Throw();
8385

MoreLinq/Lock.cs

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#if NET9_0_OR_GREATER
2+
// https://learn.microsoft.com/dotnet/csharp/language-reference/statements/lock#guidelines
3+
global using Lock = System.Threading.Lock;
4+
#else
5+
// For why "System.Object" instead of "object", see:
6+
// https://github.com/dotnet/runtime/issues/110242
7+
global using Lock = System.Object;
8+
#endif

0 commit comments

Comments
 (0)