Skip to content

Instantly share code, notes, and snippets.

@bobbychopra
Last active December 16, 2015 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bobbychopra/5445446 to your computer and use it in GitHub Desktop.
Save bobbychopra/5445446 to your computer and use it in GitHub Desktop.
Frequently Used Extension Methods
namespace System
{
public static class DateTimeExt
{
public static DateTime ToUnspecified(this DateTime dt)
{
return DateTime.SpecifyKind(dt, DateTimeKind.Unspecified);
}
}
}
namespace System
{
public static class DoubleExt
{
public static bool IsZero(this double input)
{
return Math.Abs(0 - input) < Double.Epsilon;
}
}
}
namespace System
{
public static class StringExt
{
public static bool EqualsWithCaseIgnore(this string a, string b)
{
return string.Equals(a.Trim(), b.Trim(), StringComparison.OrdinalIgnoreCase);
}
public static T As<T>(this string str)
{
if (string.IsNullOrWhiteSpace(str) && Nullable.GetUnderlyingType(typeof(T)) != null)
return default(T);
return (T)Convert.ChangeType(str, typeof(T));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment