3 changed files with 66 additions and 53 deletions
@ -1,32 +1,44 @@ |
|||
using System.Collections.Generic; |
|||
using System.Diagnostics.CodeAnalysis; |
|||
|
|||
namespace System; |
|||
using System.Runtime.CompilerServices; |
|||
|
|||
#if !NET6_0_OR_GREATER
|
|||
internal static class CollectionCompatibilityExtensions |
|||
namespace System |
|||
{ |
|||
public static bool Remove<TKey, TValue>( |
|||
this Dictionary<TKey, TValue> o, |
|||
TKey key, |
|||
[MaybeNullWhen(false)] out TValue value) |
|||
where TKey : notnull |
|||
internal static class CollectionCompatibilityExtensions |
|||
{ |
|||
if (o.TryGetValue(key, out value)) |
|||
return o.Remove(key); |
|||
return false; |
|||
} |
|||
public static bool Remove<TKey, TValue>( |
|||
this Dictionary<TKey, TValue> o, |
|||
TKey key, |
|||
[MaybeNullWhen(false)] out TValue value) |
|||
where TKey : notnull |
|||
{ |
|||
if (o.TryGetValue(key, out value)) |
|||
return o.Remove(key); |
|||
return false; |
|||
} |
|||
|
|||
public static bool TryAdd<TKey, TValue>(this Dictionary<TKey, TValue> o, TKey key, TValue value) |
|||
where TKey : notnull |
|||
public static bool TryAdd<TKey, TValue>(this Dictionary<TKey, TValue> o, TKey key, TValue value) |
|||
where TKey : notnull |
|||
{ |
|||
if (!o.ContainsKey(key)) |
|||
{ |
|||
o.Add(key, value); |
|||
return true; |
|||
} |
|||
|
|||
return false; |
|||
} |
|||
} |
|||
|
|||
namespace Runtime.InteropServices |
|||
{ |
|||
if (!o.ContainsKey(key)) |
|||
public static class CollectionsMarshal |
|||
{ |
|||
o.Add(key, value); |
|||
return true; |
|||
public static Span<T> AsSpan<T>(List<T>? list) |
|||
=> list is null ? default : new Span<T>(Unsafe.As<StrongBox<T[]>>(list).Value, 0, list.Count); |
|||
} |
|||
|
|||
return false; |
|||
} |
|||
} |
|||
|
|||
#endif
|
|||
|
|||
Loading…
Reference in new issue