C# extension methods for Base Class Library types.
The motivation behind this project is to collect reusable extension methods into a NuGet package avoiding CPD (copy-paste-development).
You can find the complete documentation here.
The documentation is generated by Sandcastle Help File Builder.
You can download the package from nuget.org.
You can find the release notes here.
There are examples below only for some of the methods. Feel free to discover all the methods in the documentation.
ThrowExtensions
(examples)T
generic type:null
string
:null
,String.Empty
or white-space onlyGuid
:Guid.Empty
ThrowExtensions
(examples)- The exception messages are in English but they can be configured.
using EgonsoftHU.Extensions.Bcl; // This method is intended to be used for non-localizable error messages. ErrorMessageConfiguration.Current.ConfigureErrorMessage( errorMessageKey: ErrorMessageKey.ArgumentOutOfRange_MustBeNonZero, errorMessage: "The parameter '{0}' must be non-zero. Actual value: {1}" ); // This method is intended to be used for localizable error messages. ErrorMessageConfiguration.Current.ConfigureErrorMessage( errorMessageKey: ErrorMessageKey.ArgumentOutOfRange_MustBeNonZero, errorMessageResourceType: typeof(YourCustomValidationResources), // This parameter is optional. If not specified then the value of errorMessageKey is used. errorMessageResourceName: "YourCustomResourceName" );
- The exception messages are in English but they can be configured.
CLR Type | C# keyword | Extension methods |
---|---|---|
System.SByte System.Int16 System.Int32 System.Int64 System.Byte System.UInt16 System.UInt32 System.UInt64 System.Half System.Single System.Double System.Decimal |
sbyte short int long byte ushort uint ulong - float double decimal |
ThrowIfZero() ThrowIfNegative() ThrowIfNegativeOrZero() ThrowIfPositive() ThrowIfPositiveOrZero() ThrowIfGreaterThan() ThrowIfGreaterThanOrEqualTo() ThrowIfLessThan() ThrowIfLessThanOrEqualTo() ThrowIfEqualTo() ThrowIfNotEqualTo() |
System.Collections.Generic.ICollection<T>
System.Collections.Generic.IDictionary<TKey, TValue>
System.Collections.Generic.IEnumerable<T>
System.DateTimeOffset
System.IO.Stream
System.Reflection.Assembly
System.Reflection.MemberInfo
System.Reflection.ParameterInfo
(examples)System.String
(examples)System.Type
- Numeric types:
System.SByte
System.Int16
System.Int32
System.Int64
System.Byte
System.UInt16
System.UInt32
System.UInt64
System.Half
System.Single
System.Double
System.Decimal
IEnumerable
-related (examples)Reflection
-related- value selectors
GuidFormat
(examples)GenericTypeDefinitions