Browse Source

Move collection polyfills to Compatibility dir.

And tweak to match existing code there.
pull/8600/head
Steven Kirk 4 years ago
parent
commit
2268f70c50
  1. 33
      src/Avalonia.Base/CollectionPolyfills.cs
  2. 32
      src/Avalonia.Base/Compatibility/CollectionCompatibilityExtensions.cs

33
src/Avalonia.Base/CollectionPolyfills.cs

@ -1,33 +0,0 @@
#if !NET6_0_OR_GREATER
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
namespace Avalonia
{
internal static class CollectionPolyfills
{
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
{
if (!o.ContainsKey(key))
{
o.Add(key, value);
return true;
}
return false;
}
}
}
#endif

32
src/Avalonia.Base/Compatibility/CollectionCompatibilityExtensions.cs

@ -0,0 +1,32 @@
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
namespace System;
#if !NET6_0_OR_GREATER
internal static class CollectionCompatibilityExtensions
{
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
{
if (!o.ContainsKey(key))
{
o.Add(key, value);
return true;
}
return false;
}
}
#endif
Loading…
Cancel
Save