Last active
December 16, 2015 13:59
-
-
Save bobbychopra/5445446 to your computer and use it in GitHub Desktop.
Frequently Used Extension Methods
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
namespace System | |
{ | |
public static class DateTimeExt | |
{ | |
public static DateTime ToUnspecified(this DateTime dt) | |
{ | |
return DateTime.SpecifyKind(dt, DateTimeKind.Unspecified); | |
} | |
} | |
} |
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
namespace System | |
{ | |
public static class DoubleExt | |
{ | |
public static bool IsZero(this double input) | |
{ | |
return Math.Abs(0 - input) < Double.Epsilon; | |
} | |
} | |
} |
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
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