Skip to content

Commit

Permalink
Allow use of C# 13
Browse files Browse the repository at this point in the history
  • Loading branch information
atifaziz authored Dec 28, 2024
1 parent 1726b52 commit 72c3c66
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<LangVersion>12</LangVersion>
<LangVersion>13</LangVersion>
<Nullable>enable</Nullable>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<AnalysisLevel>8.0-all</AnalysisLevel>
Expand Down
4 changes: 3 additions & 1 deletion MoreLinq/Experimental/Memoize.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public static IEnumerable<T> Memoize<T>(this IEnumerable<T> source) =>
sealed class MemoizedEnumerable<T>(IEnumerable<T> sequence) : IEnumerable<T>, IDisposable
{
List<T>? cache;
readonly object locker = new();
readonly Lock locker = new();
readonly IEnumerable<T> source = sequence ?? throw new ArgumentNullException(nameof(sequence));
IEnumerator<T>? sourceEnumerator;
int? errorIndex;
Expand All @@ -77,7 +77,9 @@ public IEnumerator<T> GetEnumerator()
{
lock (this.locker)
{
#pragma warning disable CA1508 // Avoid dead conditional code
if (this.cache == null)
#pragma warning restore CA1508 // Avoid dead conditional code
{
this.error?.Throw();

Expand Down
8 changes: 8 additions & 0 deletions MoreLinq/Lock.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#if NET9_0_OR_GREATER
// https://learn.microsoft.com/dotnet/csharp/language-reference/statements/lock#guidelines
global using Lock = System.Threading.Lock;
#else
// For why "System.Object" instead of "object", see:
// https://github.com/dotnet/runtime/issues/110242
global using Lock = System.Object;
#endif

0 comments on commit 72c3c66

Please sign in to comment.