Saxonite v1.2.3
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using System.Linq;
|
||||
|
||||
namespace Sarand.Net.Standard.Base.Utils
|
||||
@@ -40,7 +42,7 @@ namespace Sarand.Net.Standard.Base.Utils
|
||||
// S t r i n g - I n t U t i l i t i e s
|
||||
//-------------------------------------------------------------------
|
||||
/// <summary>Increment the count against the specified key by the supplied value, creating the key's entry if needed.</summary>
|
||||
public static void Increment (this IDictionary<String, int> dictionary, String key, int increment = 1)
|
||||
public static void Increment(this IDictionary<String, int> dictionary, String key, int increment = 1)
|
||||
{
|
||||
if (!dictionary.ContainsKey(key))
|
||||
dictionary[key] = increment;
|
||||
@@ -52,14 +54,14 @@ namespace Sarand.Net.Standard.Base.Utils
|
||||
// A d d T o L i s t V a l u e
|
||||
//-------------------------------------------------------------------
|
||||
/// <summary>Add key:object to dictionary where each value is a list of objects.</summary>
|
||||
public static void Add<TKey, TValue> (this Dictionary<TKey, List<TValue>> dict, TKey key, TValue value)
|
||||
public static void Add<TKey, TValue>(this Dictionary<TKey, List<TValue>> dict, TKey key, TValue value)
|
||||
{
|
||||
if (!dict.ContainsKey(key))
|
||||
dict[key] = new List<TValue>();
|
||||
dict[key].Add(value);
|
||||
}
|
||||
/// <summary>Add key:objects to dictionary where each value is a list of objects.</summary>
|
||||
public static void Add<TKey, TValue> (this Dictionary<TKey, List<TValue>> dict, TKey key, IEnumerable<TValue> values)
|
||||
public static void Add<TKey, TValue>(this Dictionary<TKey, List<TValue>> dict, TKey key, IEnumerable<TValue> values)
|
||||
{
|
||||
if (!dict.ContainsKey(key))
|
||||
dict[key] = new List<TValue>();
|
||||
@@ -70,11 +72,36 @@ namespace Sarand.Net.Standard.Base.Utils
|
||||
// A d d R a n g e
|
||||
//-------------------------------------------------------------------
|
||||
/// <summary>Add entries from another dictionary.</summary>
|
||||
public static void AddRange<TKey, TValue> (this Dictionary<TKey, TValue> dict, Dictionary<TKey, TValue> dictToAdd)
|
||||
public static void AddRange<TKey, TValue>(this Dictionary<TKey, TValue> dict, Dictionary<TKey, TValue> dictToAdd)
|
||||
{
|
||||
dictToAdd.ForEach(x => dict.Add(x.Key, x.Value));
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Orderd Dictionary
|
||||
//-------------------------------------------------------------------
|
||||
public static DictionaryEntry GetElementAt(this OrderedDictionary dictionary, int index)
|
||||
{
|
||||
return dictionary.Cast<DictionaryEntry>().ElementAt(index);
|
||||
}
|
||||
public static K GetKeyAt<K>(this OrderedDictionary dictionary, int index)
|
||||
{
|
||||
return (K)dictionary.GetElementAt(index).Key;
|
||||
}
|
||||
public static V GetValue<K, V>(this OrderedDictionary dictionary, K key)
|
||||
{
|
||||
if (dictionary == null || key == null)
|
||||
return default(V);
|
||||
try
|
||||
{
|
||||
return (V)dictionary.Cast<DictionaryEntry>().AsQueryable().Single(kvp => ((K)kvp.Key).Equals(key)).Value;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return default(V);
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
|
||||
Reference in New Issue
Block a user