Skip to content

Commit

Permalink
Enhance framework compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
Uralstech committed Nov 6, 2023
1 parent 6334f25 commit 1dad1ff
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 6 deletions.
4 changes: 3 additions & 1 deletion LLama/Common/FixedSizeQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,13 @@ public FixedSizeQueue(int size)
/// <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
Expand Down
4 changes: 3 additions & 1 deletion LLama/Extensions/DictionaryExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion LLama/Extensions/EncodingExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -15,6 +15,8 @@ public static int GetCharCount(this Encoding encoding, ReadOnlySpan<byte> bytes)
{
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)
Expand Down
4 changes: 3 additions & 1 deletion LLama/Extensions/IEnumerableExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion LLama/Extensions/KeyValuePairExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -19,5 +19,7 @@ public static void Deconstruct<TKey, TValue>(this System.Collections.Generic.Key
first = pair.Key;
second = pair.Value;
}
#elif !NET6_0_OR_GREATER
#error Target framework not supported!
#endif
}
4 changes: 3 additions & 1 deletion LLama/Extensions/ListExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 1dad1ff

Please sign in to comment.