Archive | Utilities RSS feed for this section

Paging and the Entity Framework, Skip, and Take Part 1

Get the total count of pages. | Get the real page number. | Using Skip and Take to Page | The Actual Paging Controls So something I’ve been doing a lot of lately is making quite possibly the best thing ever: String cheese wrapped in turkey bacon. But when I’m not doing that, I am [...]

2 Comments Continue Reading →

Duck Typing my way to a Universal String Convert

So being the beacon of ignorance in the fog of brilliance, I had no idea what Duck Typing was. In short it’s the idea of assuming a class’s type based on the methods it holds. Say you have 5 different classes, none of which share an inheritance tree. Now let’s say you have a method [...]

Leave a comment Continue Reading →

Convert Enum to Dictionary: Another Silly Method

So what if you want the names and values from an Enum, but wanted them in dictionary form. Well shoot, a little bit of linq and little bit of that and you got this: public static IDictionary<String, Int32> ConvertEnumToDictionary<K>() { if (typeof(K).BaseType != typeof(Enum)) { throw new InvalidCastException(); } return Enum.GetValues(typeof(K)).Cast<Int32>().ToDictionary(currentItem => Enum.GetName(typeof(K), currentItem)); } [...]

1 Comment Continue Reading →

Yeah SessionTryParse

So I got tired of seeing If Session["SomeKey"] != null… blah blah blah and thought it would be a semi worthwhile task to create a TryParse method because I’m bad like that. Not a Bad Enough Dude to Save the President, but bad. public static Boolean SessionTryParse<K&gt;(HttpSessionState session, String key, out K itemToSet) where K [...]

Leave a comment Continue Reading →

Convert a String to a Number String With Linq… YAY

Really stupid little thing I came up with today… but I wanted to use Linq to strip any non number from a string and return the string with only numbers. I told you this was a stupid little thing. public static String CreateNumberOnlyString(String textToCheck) { String returnText; var queryForIntegers = from currentChar in textToCheck where [...]

Leave a comment Continue Reading →