Enhance framework compatibility
This commit is contained in:
parent
6334f25627
commit
1dad1ff834
|
@ -43,11 +43,13 @@ namespace LLama.Common
|
|||
/// <param name="data"></param>
|
||||
public FixedSizeQueue(int size, IEnumerable<T> data)
|
||||
{
|
||||
#if !NETSTANDARD2_0
|
||||
#if NET6_0_OR_GREATER
|
||||
// Try to check the size without enumerating the entire IEnumerable. This may not be able to get the count,
|
||||
// in which case we'll have to check later
|
||||
if (data.TryGetNonEnumeratedCount(out var dataCount) && dataCount > size)
|
||||
throw new ArgumentException($"The max size set for the quene is {size}, but got {dataCount} initial values.");
|
||||
#elif !NETSTANDARD2_0_OR_GREATER
|
||||
#error Target framework not supported!
|
||||
#endif
|
||||
|
||||
// Size of "data" is unknown, copy it all into a list
|
||||
|
|
|
@ -4,11 +4,13 @@ namespace LLama.Extensions
|
|||
{
|
||||
internal static class DictionaryExtensions
|
||||
{
|
||||
#if NETSTANDARD2_0
|
||||
#if NETSTANDARD2_0_OR_GREATER
|
||||
public static TValue GetValueOrDefault<TKey, TValue>(this IReadOnlyDictionary<TKey, TValue> dictionary, TKey key, TValue defaultValue)
|
||||
{
|
||||
return GetValueOrDefaultImpl(dictionary, key, defaultValue);
|
||||
}
|
||||
#elif !NET6_0_OR_GREATER
|
||||
#error Target framework not supported!
|
||||
#endif
|
||||
|
||||
internal static TValue GetValueOrDefaultImpl<TKey, TValue>(IReadOnlyDictionary<TKey, TValue> dictionary, TKey key, TValue defaultValue)
|
||||
|
|
|
@ -5,7 +5,7 @@ namespace LLama.Extensions;
|
|||
|
||||
internal static class EncodingExtensions
|
||||
{
|
||||
#if NETSTANDARD2_0
|
||||
#if NETSTANDARD2_0_OR_GREATER
|
||||
public static int GetChars(this Encoding encoding, ReadOnlySpan<byte> bytes, Span<char> output)
|
||||
{
|
||||
return GetCharsImpl(encoding, bytes, output);
|
||||
|
@ -15,6 +15,8 @@ internal static class EncodingExtensions
|
|||
{
|
||||
return GetCharCountImpl(encoding, bytes);
|
||||
}
|
||||
#elif !NET6_0_OR_GREATER
|
||||
#error Target framework not supported!
|
||||
#endif
|
||||
|
||||
internal static int GetCharsImpl(Encoding encoding, ReadOnlySpan<byte> bytes, Span<char> output)
|
||||
|
|
|
@ -5,11 +5,13 @@ namespace LLama.Extensions
|
|||
{
|
||||
internal static class IEnumerableExtensions
|
||||
{
|
||||
#if NETSTANDARD2_0
|
||||
#if NETSTANDARD2_0_OR_GREATER
|
||||
public static IEnumerable<T> TakeLast<T>(this IEnumerable<T> source, int count)
|
||||
{
|
||||
return TakeLastImpl(source, count);
|
||||
}
|
||||
#elif !NET6_0_OR_GREATER
|
||||
#error Target framework not supported!
|
||||
#endif
|
||||
|
||||
internal static IEnumerable<T> TakeLastImpl<T>(IEnumerable<T> source, int count)
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
/// </summary>
|
||||
internal static class KeyValuePairExtensions
|
||||
{
|
||||
#if NETSTANDARD2_0
|
||||
#if NETSTANDARD2_0_OR_GREATER
|
||||
/// <summary>
|
||||
/// Deconstruct a KeyValuePair into it's constituent parts.
|
||||
/// </summary>
|
||||
|
@ -19,5 +19,7 @@ internal static class KeyValuePairExtensions
|
|||
first = pair.Key;
|
||||
second = pair.Value;
|
||||
}
|
||||
#elif !NET6_0_OR_GREATER
|
||||
#error Target framework not supported!
|
||||
#endif
|
||||
}
|
|
@ -5,12 +5,14 @@ namespace LLama.Extensions
|
|||
{
|
||||
internal static class ListExtensions
|
||||
{
|
||||
#if NETSTANDARD2_0
|
||||
#if NETSTANDARD2_0_OR_GREATER
|
||||
public static void EnsureCapacity<T>(this List<T> list, int capacity)
|
||||
{
|
||||
if (list.Capacity < capacity)
|
||||
list.Capacity = capacity;
|
||||
}
|
||||
#elif !NET6_0_OR_GREATER
|
||||
#error Target framework not supported!
|
||||
#endif
|
||||
|
||||
public static void AddSpan<T>(this List<T> list, ReadOnlySpan<T> items)
|
||||
|
|
Loading…
Reference in New Issue