Extension Methods from Phil Campbell
-
WhereIf
When building a LINQ query, you may need to involve optional filtering criteria. Avoids if statements when building predicates & lambdas for a query. Useful when you don't know at compile time whether a filter should apply. Borrowed from Andrew Robinson. http://bit.ly/1V36G9
-
IsDate
Wraps DateTime.TryParse() and all the other kinds of code you need to determine if a given string holds a value that can be converted into a DateTime object.
-
Randomize
OrderBy() is nice when you want a consistent & predictable ordering. This method is NOT THAT! Randomize() - Use this extension method when you want a different or random order every time! Useful when ordering a list of things for display to give each a fair chance of landing at the top or bottom on each hit. {customers, support techs, or even use as a randomizer for your lottery ;) }
-
EqualsAny
Check that the given string is in a list of potential matches. Inspired by StackOverflow answer http://stackoverflow.com/a/20644611/23199
-
Or
Returns the first string with a non-empty non-null value.
-
Length
Determines how many numbers compose the integer if it was represented as a string.
-
HasMultipleInstancesOf
Determines whether a string has multiple occurrences of a particular character. May be helpful when parsing file names, or ensuring a particular string has already contains a given character. This may be extended to use strings, rather than a char.