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);
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace Sarand.Net.Standard.Base.Utils
|
||||
/// <para>- \r\n replaced with \n</para>
|
||||
/// <para>- Duplicate lines removed.</para>
|
||||
/// </summary>
|
||||
public static String GetMessage (this Exception exc)
|
||||
public static String GetMessage(this Exception exc)
|
||||
{
|
||||
List<String> messageLines = new List<string>();
|
||||
foreach (String messageLine in (StringUtil.EmptyOnNull(exc?.Message) ?? "").Trim().ReplaceAll("\r\n", "\n").Split('\n'))
|
||||
@@ -29,7 +29,7 @@ namespace Sarand.Net.Standard.Base.Utils
|
||||
/// <para>[ExceptionType]: [ExceptionMessage]</para>
|
||||
/// <para>followed by stack entries on separate lines.</para>
|
||||
/// </summary>
|
||||
public static String GetErrorStateMessage (this Exception exc, bool includeExceptionType = true)
|
||||
public static String GetErrorStateMessage(this Exception exc, bool includeExceptionType = true)
|
||||
{
|
||||
return (includeExceptionType ? exc.GetType().Name + ": " : "") + GetMessage(exc);
|
||||
}
|
||||
@@ -40,14 +40,23 @@ namespace Sarand.Net.Standard.Base.Utils
|
||||
/// <para>[ExceptionType]: [ExceptionMessage]</para>
|
||||
/// <para>followed by stack entries on separate lines.</para>
|
||||
/// </summary>
|
||||
public static String GetLogMessage (this Exception exc, int entries = 8, String stackEntryDelim = "\n\t")
|
||||
public static String GetLogMessage(this Exception exc, int entries = 8, String stackEntryDelim = "\n\t")
|
||||
{
|
||||
return exc.GetType().Name + ": " + GetMessage(exc) + exc.GetStackEntries(entries).Concat("", stackEntryDelim);
|
||||
return exc.GetLogMessage("", entries, stackEntryDelim);
|
||||
}
|
||||
/// <summary>
|
||||
/// Generate standard exception log message.
|
||||
/// <para>[ExceptionType] [message]: [ExceptionMessage]</para>
|
||||
/// <para>followed by stack entries on separate lines.</para>
|
||||
/// </summary>
|
||||
public static String GetLogMessage(this Exception exc, String message, int entries = 8, String stackEntryDelim = "\n\t")
|
||||
{
|
||||
return (exc.GetType().Name + " " + message + ": " + GetMessage(exc) + exc.GetStackEntries(entries).Concat("", stackEntryDelim)).TrimAll();
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
/// <summary>Retrieve stack entries, up to maximum number.</summary>
|
||||
public static List<String> GetStackEntries (this Exception exc, int entries = 0)
|
||||
public static List<String> GetStackEntries(this Exception exc, int entries = 0)
|
||||
{
|
||||
List<String> stackEntries = new List<string>();
|
||||
stackEntries.AddRange(exc.StackTrace.Split(new String[] { "\r\n" }, (entries > 0 ? entries : 999), StringSplitOptions.None));
|
||||
@@ -63,19 +72,19 @@ namespace Sarand.Net.Standard.Base.Utils
|
||||
// File handling exceptions.
|
||||
public class FileException : Exception
|
||||
{
|
||||
public FileException (string message) :
|
||||
public FileException(string message) :
|
||||
base(message)
|
||||
{ }
|
||||
}
|
||||
public class ArchiveFileException : FileException
|
||||
{
|
||||
public ArchiveFileException (string message) :
|
||||
public ArchiveFileException(string message) :
|
||||
base(message)
|
||||
{ }
|
||||
}
|
||||
public class FileExistsException : FileException
|
||||
{
|
||||
public FileExistsException (string message) :
|
||||
public FileExistsException(string message) :
|
||||
base(message)
|
||||
{ }
|
||||
}
|
||||
|
||||
@@ -42,18 +42,18 @@ namespace Sarand.Net.Standard.Base.Utils
|
||||
// C o m p a r i s o n
|
||||
//-------------------------------------------------------------------
|
||||
/// <summary>Compare lists to verify that they contain the same value in the corresponding position.</summary>
|
||||
public static bool ContentEquals (this List<String> values, List<String> target)
|
||||
public static bool ContentEquals (this IEnumerable<String> values, IEnumerable<String> target)
|
||||
{
|
||||
if (values.Count != target.Count) return false;
|
||||
if (values.Count() != target.Count()) return false;
|
||||
var combinedValues = values.Zip(target, Tuple.Create);
|
||||
foreach (var combinedValue in combinedValues)
|
||||
if (!combinedValue.Item1.Equals(combinedValue.Item2)) return false;
|
||||
return true;
|
||||
}
|
||||
/// <summary>Compare lists to verify that they contain the same case-insensitive value in the corresponding position.</summary>
|
||||
public static bool ContentEqualsCI (this List<String> values, List<String> target)
|
||||
public static bool ContentEqualsCI (this IEnumerable<String> values, IEnumerable<String> target)
|
||||
{
|
||||
if (values.Count != target.Count) return false;
|
||||
if (values.Count() != target.Count()) return false;
|
||||
var combinedValues = values.Zip(target, Tuple.Create);
|
||||
foreach (var combinedValue in combinedValues)
|
||||
if (!combinedValue.Item1.EqualsCI(combinedValue.Item2)) return false;
|
||||
|
||||
Reference in New Issue
Block a user