Browse Source

Merge pull request #55 from martindevans/removed_dictionary_extensions

Cleaned up unnecessary extension methods
tags/v0.4.2-preview
Rinne GitHub 2 years ago
parent
commit
dee9afc471
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 30 deletions
  1. +0
    -30
      LLama/Extensions/DictionaryExtensions.cs
  2. +24
    -0
      LLama/Extensions/KeyValuePairExtensions.cs

+ 0
- 30
LLama/Extensions/DictionaryExtensions.cs View File

@@ -1,30 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace LLama.Extensions
{
public static class DictionaryExtension
{
public static void Deconstruct<T1, T2>(this KeyValuePair<T1, T2> pair, out T1 first, out T2 second)
{
first = pair.Key;
second = pair.Value;
}
public static void Update<T1, T2>(this Dictionary<T1, T2> dic, IDictionary<T1, T2> other)
{
foreach (var (key, value) in other)
{
dic[key] = value;
}
}
public static T2 GetOrDefault<T1, T2>(this Dictionary<T1, T2> dic, T1 key, T2 defaultValue)
{
if (dic.ContainsKey(key))
{
return dic[key];
}
return defaultValue;
}
}
}

+ 24
- 0
LLama/Extensions/KeyValuePairExtensions.cs View File

@@ -0,0 +1,24 @@
using System.Collections.Generic;

namespace LLama.Extensions
{
/// <summary>
/// Extensions to the KeyValuePair struct
/// </summary>
public static class KeyValuePairExtensions
{
/// <summary>
/// Deconstruct a KeyValuePair into it's constituent parts.
/// </summary>
/// <param name="pair">The KeyValuePair to deconstruct</param>
/// <param name="first">First element, the Key</param>
/// <param name="second">Second element, the Value</param>
/// <typeparam name="TKey">Type of the Key</typeparam>
/// <typeparam name="TValue">Type of the Value</typeparam>
public static void Deconstruct<TKey, TValue>(this KeyValuePair<TKey, TValue> pair, out TKey first, out TValue second)
{
first = pair.Key;
second = pair.Value;
}
}
}

Loading…
Cancel
Save