Skip to content

A list of extension methods for commonly used functionality

Notifications You must be signed in to change notification settings

DemetriouJohn/SmartExtensions

Repository files navigation

SmartExtensions

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.

.NET Core Build and Run Unit Tests

Installation

Install-Package SmartExtensionMethods

Currently Available Extension methods (84)

StringExtensions

  1. CaseInsensitiveContains Checks if string is contained using case insensitive search
  2. CaseInsensitiveCompare Compares two string using insensitive case
  3. ToValueOrDefault Returns value or if null, returns provided default value
  4. IsNullOrEmpty Checks if string is null or empty
  5. IsNullOrWhitespace Checks if string is null or white space
  6. RemoveSpaces Removes all spaces from string
  7. TryToInt16 Casts string to short using the try pattern
  8. TryToInt32 Casts string to int using the try pattern
  9. TryToInt64 Casts string to long using the try pattern
  10. TryToDate Casts string to date using the try pattern
  11. TryToDecimal Casts string to decimal using the try pattern
  12. TryToDouble Casts string to double using the try pattern
  13. Reverse Reverses the string
  14. IsEmail Checks if string is an email string
  15. ExtractEmail Returns a new string containing an email from the original string. If no email found returns String.empty
  16. IsPhone Checks if string resembles a phone number
  17. IsPalindrome Checks if string is a palindrome
  18. ContainsAll Check whether the specified string contains an array of strings for each.
  19. DeserializeXml<T> Deserializes string XML to type <T>.
  20. Nl2Br Converts Windows and Linux new line characters to HTML break characters
  21. EqualsAny Check that the given string is in a list of potential matches.
  22. Join Joins a list of strings with the provided separator
  23. JoinWithComma Joins a list of strings with ", "
  24. JoinWithSpace Joins a list of strings with a single space
  25. GetEnumValue Get Enum value (case inssensitive) or return provided default if not found
  26. ToCamelCase Converts a string with spaces to a string with camelCase representation

DoubleExtensions

  1. IsNaN
  2. IsInfinity
  3. GetPercentage Returns a value representing the percentage requested
  4. Pow Extension 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 faster
  5. KB Returns value in Kilobytes
  6. MB Returns value in Megabytes
  7. GB Returns value in Gigabytes
  8. TB Returns value in Terabytes

FloatExtensions

  1. IsNaN
  2. IsInfinity
  3. GetPercentage Returns a value representing the percentage requested
  4. Pow Extension 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 faster
  5. KB Returns value in Kilobytes
  6. MB Returns value in Megabytes
  7. GB Returns value in Gigabytes
  8. TB Returns value in Terabytes

IntExtensions

  1. GetPercentage Returns a value representing the percentage requested
  2. Pow Extension 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 faster
  3. KB Returns value in Kilobytes
  4. MB Returns value in Megabytes
  5. GB Returns value in Gigabytes
  6. TB Returns value in Terabytes
  7. IsPrime Checks if number is Prime

ShortExtensions

  1. GetPercentage Returns a value representing the percentage requested
  2. Pow Extension 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 faster
  3. KB Returns value in Kilobytes
  4. MB Returns value in Megabytes
  5. GB Returns value in Gigabytes
  6. TB Returns value in Terabytes
  7. IsPrime Checks if number is Prime

DateTimeExtensions

  1. FirstDayOfMonth Get first day of the month
  2. FirstDayOfMonth Get first specific day of the month
  3. NextSpecificDay Next specific day
  4. LastDayOfMonth Get last day of the month
  5. LastDayOfMonth Get last specific day of the month
  6. SetTime Get DateTime with specific time. Overloads for minute accuracy, second accuracy and milisecond accuracy
  7. GetNoon Gets a DateTime representing noon on the current date
  8. GetMidnight Gets a DateTime representing midnight on the current date
  9. Age Gets the age of a person
  10. ToUnixEpoch Converts UTC time to Unix time
  11. FromUnixEpoch Converts Unix time to UTC time
  12. FirstBusinessDayOfMonth Gets a DateTime representing the first business day of the month of the provided DateTime
  13. FirstBusinessDayOfMonth Gets a DateTime representing the first business day of the month of the provided DateTime that is not part of a given holidays list
  14. LastBusinessDayOfMonth Gets a DateTime representing the last business day of the month of the provided DateTime
  15. LastBusinessDayOfMonth Gets a DateTime representing the last business day of the month of the provided DateTime that is not part of a given holidays list

IEnumerableExtensions

  1. Sum Introduced sum method for LINQ usage for TimeSpans
  2. IsNullOrEmpty Checks if Enumerable is null or empty
  3. Foreach Executes provided action on each item of the Enumerable
  4. StandardDeviation <int> Performs Standard Deviation on the entire dataset
  5. StandardDeviationPopulation <int> Performs Standard Deviation on the entire dataset (Population)
  6. ToHashSet<T> Takes any IEnumerable and converts it to a HashSet
  7. GetRandomSubset<T> Takes any IEnumerable and returns a new IEnumerable that represent a random subset

XmlDocumentExtensions

  1. AppendXml Append one or multiple XML documents to the current XML document
  2. DeserializeXml<T> Deserializes XMLDocument to type <T>.

TimeSpanExtensions

  1. MilliSeconds Get TimeSpan.FromMilliSeconds() from int and double
  2. Seconds Get TimeSpan.FromSeconds() from int and double
  3. Minutes Get TimeSpan.FromMinutes() from int and double
  4. Hours Get TimeSpan.FromHours() from int and double
  5. Days Get TimeSpan.FromDays() from int and double

Contributing

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.

About

A list of extension methods for commonly used functionality

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages