Created
August 29, 2013 09:28
-
-
Save Krummelz/6376051 to your computer and use it in GitHub Desktop.
Everyone loves 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
public static bool IsNumeric(this string s) | |
{ | |
double d = 0.0; | |
return (double.TryParse(s, out d)); | |
} | |
public static int? ToIntegerNullable(this string s) | |
{ | |
int i = 0; | |
if (int.TryParse(s, out i)) | |
return i; | |
else | |
return null; | |
} | |
public static int ToInteger(this string s) | |
{ | |
int i = 0; | |
if (int.TryParse(s, out i)) | |
return i; | |
else | |
return 0; | |
} | |
public static double ToDouble(this string s) | |
{ | |
double d = 0; | |
if (double.TryParse(s, out d)) | |
return d; | |
else | |
return 0; | |
} | |
public static decimal ToDecimal(this string s) | |
{ | |
decimal d = 0.0m; | |
if (decimal.TryParse(s, out d)) | |
return d; | |
else | |
return 0.0m; | |
} | |
public static string ToFormattedDateTime(this string s) | |
{ | |
DateTime dt; | |
if (!DateTime.TryParse(s, out dt)) | |
return ""; | |
else | |
return dt.ToString("dd MMM yyyy"); | |
} | |
public static UserDetail GetUserDetails(this MembershipUser user) | |
{ | |
Model.Entities _db = new Model.Entities(); | |
return _db.UserDetails.Where(ud => ud.Email == user.UserName).First(); | |
} | |
public static List<string> AppendPleaseSelect(this List<string> list) | |
{ | |
list.Insert(0, "Please Select.."); | |
return list; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment