2019-11-14 19:42:25 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Text.RegularExpressions;
|
2019-11-14 18:08:21 +00:00
|
|
|
|
|
|
|
|
|
namespace BFR.Helpers
|
|
|
|
|
{
|
|
|
|
|
public static class IListExtensions
|
|
|
|
|
{
|
|
|
|
|
public static void ReplaceAll<T>(this IList<T> list, IEnumerable<T> replacement)
|
|
|
|
|
{
|
|
|
|
|
list.Clear();
|
|
|
|
|
foreach (var t in replacement)
|
|
|
|
|
list.Add(t);
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-11-14 19:42:25 +00:00
|
|
|
|
|
|
|
|
|
public static class StringExtensions
|
|
|
|
|
{
|
|
|
|
|
public static string Replace(this string input, string pattern, string replacement, bool useRegex = false, bool useRegexReplace = false) =>
|
|
|
|
|
Regex.Replace(input,
|
|
|
|
|
useRegex ? pattern : Regex.Escape(pattern),
|
|
|
|
|
useRegexReplace ? replacement : replacement.Replace("$", "$$"));
|
|
|
|
|
|
|
|
|
|
public static bool RegexContains(this string input, string pattern)
|
|
|
|
|
{
|
|
|
|
|
try { return Regex.IsMatch(input, pattern); }
|
|
|
|
|
catch(Exception) { return false; }
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-11-21 18:07:46 +00:00
|
|
|
|
|
|
|
|
|
public static class EnumExtensions
|
|
|
|
|
{
|
|
|
|
|
public static T GetAttribute<T>(this Enum enumVal) where T : Attribute
|
|
|
|
|
{
|
|
|
|
|
var type = enumVal.GetType();
|
|
|
|
|
var memInfo = type.GetMember(enumVal.ToString());
|
|
|
|
|
var attributes = memInfo[0].GetCustomAttributes(typeof(T), false);
|
|
|
|
|
return (attributes.Length > 0) ? (T)attributes[0] : null;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-11-14 18:08:21 +00:00
|
|
|
|
}
|