From 62dc2943ffb5ae07f3f016b2ecb9cca6e1be6333 Mon Sep 17 00:00:00 2001 From: Atif Aziz Date: Sat, 28 Dec 2024 23:00:40 +0100 Subject: [PATCH] Allow use of C# 13 --- Directory.Build.props | 2 +- MoreLinq/Experimental/Memoize.cs | 2 +- MoreLinq/Lock.cs | 8 ++++++++ 3 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 MoreLinq/Lock.cs diff --git a/Directory.Build.props b/Directory.Build.props index 222a1c0a6..cecc99270 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,6 +1,6 @@ - 12 + 13 enable true 8.0-all diff --git a/MoreLinq/Experimental/Memoize.cs b/MoreLinq/Experimental/Memoize.cs index 8e6a3c6b5..9e1cfb68b 100644 --- a/MoreLinq/Experimental/Memoize.cs +++ b/MoreLinq/Experimental/Memoize.cs @@ -65,7 +65,7 @@ public static IEnumerable Memoize(this IEnumerable source) => sealed class MemoizedEnumerable(IEnumerable sequence) : IEnumerable, IDisposable { List? cache; - readonly object locker = new(); + readonly Lock locker = new(); readonly IEnumerable source = sequence ?? throw new ArgumentNullException(nameof(sequence)); IEnumerator? sourceEnumerator; int? errorIndex; diff --git a/MoreLinq/Lock.cs b/MoreLinq/Lock.cs new file mode 100644 index 000000000..ce65fc442 --- /dev/null +++ b/MoreLinq/Lock.cs @@ -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