This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Run an action after the specified delay | |
/// </summary> | |
/// <param name="delayMillis">millisecond delay before running an action</param> | |
/// <param name="doOnce">action to run</param> | |
public static void RunOneShot(int delayMillis, Action doOnce) | |
{ | |
if (delayMillis <= 0) throw new ArgumentException("RunOneShot delayMillis argument must be greater than 0"); | |
if (doOnce == null) throw new ArgumentException("RunOneShot doOnce argument cannot be null"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static class EntityHelper | |
{ | |
/// <summary> | |
/// Makes a shallow copy of an entity object. This works much like a MemberwiseClone() | |
/// but directly instantiates a new object and copies only properties that work with | |
/// EF and don't have the NotMappedAttribute. | |
/// | |
/// ** It also avoids copying the EF's proxy reference that would occur by using MemberwiseClone() ** | |
/// |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
string regex = @"\A(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)\Z"; | |
bool isEmail = Regex.IsMatch(emailString, regex, RegexOptions.IgnoreCase); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// expected usage: var tableRec = Utils.CopyProperties<StatDbRecord>(fileRow, typeof(IStat)); | |
static public class Utils | |
{ | |
static public TDst CopyProperties<TDst>(object src, Type hasProps) where TDst : class, new() | |
{ | |
var dst = new TDst(); | |
foreach (var propInf in hasProps.GetProperties()) | |
{ | |
var val = propInf.GetValue(src, null); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using Xunit; | |
using Moq; | |
public class Program | |
{ | |
static void Main(string[] args) | |
{ | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class TestUtil | |
{ | |
private static Random _random = new Random(); | |
public static string MakeRandomString(int numchars = 8) | |
{ | |
const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz"; | |
return new string(Enumerable.Repeat(chars, numchars).Select(x => x[_random.Next(x.Length)]).ToArray()); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Regex.Match(fullstring, @"\b" + findstr + @"\b", RegexOptions.IgnoreCase).Success | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static bool IsNumeric(this string str) | |
{ | |
decimal dec; | |
bool numeric = decimal.TryParse(str, out dec); | |
if (!numeric) | |
{ | |
// this will handle scientific notation (e.g., "314e-2") | |
numeric = decimal.TryParse(str, System.Globalization.NumberStyles.Float, null, out dec); | |
} | |
return numeric; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Return the text found between two other substrings. | |
public static string Substring(this string src, string startStr, string finishStr) | |
{ | |
string substr = ""; | |
int atStart = src.IndexOf(startStr); | |
if (atStart >= 0) | |
{ | |
int afterStart = atStart + startStr.Length; | |
int atFinish = src.IndexOf(finishStr, afterStart); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// System.Collections.Generic.KeyValuePair has not setters so we have to roll our own in order to serialize. | |
/// </summary> | |
[Serializable] | |
[XmlType(TypeName = "KVP")] | |
public struct SerializableKeyValuePair<K, V> | |
{ | |
public K Key { get; set; } | |
public V Value { get; set; } | |
} |
OlderNewer