Useful extensions for .net framework types. This is a pure utility package and should be kept as simple as possible but also as powerful as possible :)
Install NuGet Package Acme.Core.Extensions from Package Manager or from Package Manager Console:
PM> Install-Package Acme.Core.Extensions
After installation you have access to a new namespace :
using Acme.Core.Extensions;
- Add a method ThrowIfZero
- Downgrade reference to StyleCop.Analyzers to 1.0.2
- Add a method SecurityHelper.CreateCryptographicallySecureGuid
- Change the Exception from EnsureNotNull to a ObjectIsNullException to avoid confusion with the ParameterNullException.
- Added DateTimeExtensions.DateOrNull
- Added ObjectExtensions.ExecuteOrNull
- Added StringExtensions.ReplaceSpecialChars
- Added ByteArrayExtensions.ToHexadecimalString
- Added DateTimeExtensions.ToUnixTimeStamp
- Added ObjectExtensions.EnsureNotNull
- Added ObjectExtensions.ThrowIfNull
- Unit tests to keep a coverage above 80%
- Keep library compatible with .Net Framework, .Net Core and .Net Standard
- Avoid too many references to external libraries
Secure your web site/application with a simple package.
https://github.com/olibos/Acme.Web.Security.Headers
All the library is self documented with XmlDoc, but here you can find some code sample. You can also have a look at the unit test project, it contains most of the extensions and how to use it.
- ToHexadecimalString : Convert a byte array into his hexadecimal string
- DateOrNull : Returns the Date property of the object of the date is not null. Otherwise, returns null.
- ToUnixTimeStamp : Convert a datetime to a UNIX timestamp (i.e. : number of seconds since unix Epoch)
- EnsureNotNull : Throws an ArgumentNullException if the object is null, or return the object. Help to validate that parameters are not null and follow. Works with class and nullable struct. Read more : https://docs.microsoft.com/en-us/visualstudio/code-quality/ca1062-validate-arguments-of-public-methods
- ExecuteOrNull : Execute a call on the source if null, or return the default for the type TReturn.
- ThrowIfNull : Throws an ArgumentNullException if the object is null. Help to validate that parameters are not null and follow. Works with class and nullable struct. Read more : https://docs.microsoft.com/en-us/visualstudio/code-quality/ca1062-validate-arguments-of-public-methods
- ThrowIfZero : Throws an ArgumentNullException if the object is null or if the value equals 0.
- ReplaceSpecialChars : Remove all special chars and accent from a string, can also replace spaces with '-'
- SHA512 : Generate a SHA512 from the string.
- CreateCryptographicallySecureGuid : Create a guid that is secure and not predictable.