Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow use of C# 13 #1094

Merged
merged 2 commits into from
Dec 28, 2024
Merged
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
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
Loading