A big list of commonly used methods and extension methods when using C# built-in types. Methods and extensions all of us write often enough to render grouping them in a nuget package useful.
Install-Package SmartExtensionMethods
CaseInsensitiveContainsChecks if string is contained using case insensitive searchCaseInsensitiveCompareCompares two string using insensitive caseToValueOrDefaultReturns value or if null, returns provided default valueIsNullOrEmptyChecks if string is null or emptyIsNullOrWhitespaceChecks if string is null or white spaceRemoveSpacesRemoves all spaces from stringTryToInt16Casts string to short using the try patternTryToInt32Casts string to int using the try patternTryToInt64Casts string to long using the try patternTryToDateCasts string to date using the try patternTryToDecimalCasts string to decimal using the try patternTryToDoubleCasts string to double using the try patternReverseReverses the stringIsEmailChecks if string is an email stringExtractEmailReturns a new string containing an email from the original string. If no email found returns String.emptyIsPhoneChecks if string resembles a phone numberIsPalindromeChecks if string is a palindromeContainsAllCheck whether the specified string contains an array of strings for each.DeserializeXml<T>Deserializes string XML to type <T>.Nl2BrConverts Windows and Linux new line characters to HTML break charactersEqualsAnyCheck that the given string is in a list of potential matches.JoinJoins a list of strings with the provided separatorJoinWithCommaJoins a list of strings with ", "JoinWithSpaceJoins a list of strings with a single spaceGetEnumValueGet Enum value (case inssensitive) or return provided default if not foundToCamelCaseConverts a string with spaces to a string with camelCase representation
IsNaNIsInfinityGetPercentageReturns a value representing the percentage requestedPowExtension method for performing Pow arithmetic expression when Power is a positive non-zero, non floating point number by using loop implementation as it is benchmarked to be fasterKBReturns value in KilobytesMBReturns value in MegabytesGBReturns value in GigabytesTBReturns value in Terabytes
IsNaNIsInfinityGetPercentageReturns a value representing the percentage requestedPowExtension method for performing Pow arithmetic expression when Power is a positive non-zero, non floating point number by using loop implementation as it is benchmarked to be fasterKBReturns value in KilobytesMBReturns value in MegabytesGBReturns value in GigabytesTBReturns value in Terabytes
GetPercentageReturns a value representing the percentage requestedPowExtension method for performing Pow arithmetic expression when Power is a positive non-zero, non floating point number by using loop implementation as it is benchmarked to be fasterKBReturns value in KilobytesMBReturns value in MegabytesGBReturns value in GigabytesTBReturns value in TerabytesIsPrimeChecks if number is Prime
GetPercentageReturns a value representing the percentage requestedPowExtension method for performing Pow arithmetic expression when Power is a positive non-zero, non floating point number by using loop implementation as it is benchmarked to be fasterKBReturns value in KilobytesMBReturns value in MegabytesGBReturns value in GigabytesTBReturns value in TerabytesIsPrimeChecks if number is Prime
FirstDayOfMonthGet first day of the monthFirstDayOfMonthGet first specific day of the monthNextSpecificDayNext specific dayLastDayOfMonthGet last day of the monthLastDayOfMonthGet last specific day of the monthSetTimeGet DateTime with specific time. Overloads for minute accuracy, second accuracy and milisecond accuracyGetNoonGets a DateTime representing noon on the current dateGetMidnightGets a DateTime representing midnight on the current dateAgeGets the age of a personToUnixEpochConverts UTC time to Unix timeFromUnixEpochConverts Unix time to UTC timeFirstBusinessDayOfMonthGets a DateTime representing the first business day of the month of the provided DateTimeFirstBusinessDayOfMonthGets a DateTime representing the first business day of the month of the provided DateTime that is not part of a given holidays listLastBusinessDayOfMonthGets a DateTime representing the last business day of the month of the provided DateTimeLastBusinessDayOfMonthGets a DateTime representing the last business day of the month of the provided DateTime that is not part of a given holidays list
SumIntroduced sum method for LINQ usage for TimeSpansIsNullOrEmptyChecks if Enumerable is null or emptyForeachExecutes provided action on each item of the EnumerableStandardDeviation <int>Performs Standard Deviation on the entire datasetStandardDeviationPopulation <int>Performs Standard Deviation on the entire dataset (Population)ToHashSet<T>Takes any IEnumerable and converts it to a HashSetGetRandomSubset<T>Takes any IEnumerable and returns a new IEnumerable that represent a random subset
AppendXmlAppend one or multiple XML documents to the current XML documentDeserializeXml<T>Deserializes XMLDocument to type <T>.
MilliSecondsGet TimeSpan.FromMilliSeconds() from int and doubleSecondsGet TimeSpan.FromSeconds() from int and doubleMinutesGet TimeSpan.FromMinutes() from int and doubleHoursGet TimeSpan.FromHours() from int and doubleDaysGet TimeSpan.FromDays() from int and double
Contributions are always welcome! Please feel free to submit pull requests and to open issues. I prefer to have tests on all public methods if possible and where ever else makes sense.