C# extension methods for Base Class Library types.
- Extension methods for throwing
ArgumentNullException - Extension methods for throwing
ArgumentException - Extension methods for throwing
ArgumentOutOfRangeException - Extension methods for specific types
- Extension methods with generic type parameters
- Predefined (
const/readonly) values - More information
- For generic
Ttype:ThrowIfNull<T>()throwsArgumentNullException
- For
System.Stringtype:ThrowIfNullOrEmpty()throwsArgumentNullExceptionorArgumentExceptionThrowIfNullOrWhiteSpace()throwsArgumentNullExceptionorArgumentException
- For
System.Guidtype:ThrowIfEmptyGuid()throwsArgumentException
Would you like to use the new static methods in ArgumentOutOfRangeException that were introduced in .NET 8 but your project targets an older framework?
In this package they are available as extension methods.
- For
IEquatable<T>type:ThrowIfEqualTo()ThrowIfNotEqualTo()
- For
IComparable<T>type:ThrowIfLessThan()ThrowIfLessThanOrEqualTo()ThrowIfGreaterThanThrowIfGreaterThanOrEqualTo()
- For 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.DecimalThrowIfZero()ThrowIfNegative()ThrowIfNegativeOrZero()ThrowIfPositive()ThrowIfPositiveOrZero()
This package contains extension methods for these types:
System.Collections.Generic.ICollection<T>AddRange()
System.Collections.Generic.IDictionary<TKey, TValue>AsReadOnly()AsSorted()DefaultIfKeyNotFound()GetOrThrow()
System.Collections.Generic.IEnumerable<T>IsNullOrEmpty()DetectChanges()- Get new, existing and removed items.
System.Collections.Generic.IList<T>AsReadOnly()up to .NET 6 (An extension method with the same signature is part of .NET 7+.)
System.DateOnlyIsInRange()
System.DateTimeIsInRange()ToMinutePrecision()ToSecondPrecision()
System.DateTimeOffsetIsInRange()ToMinutePrecision()ToSecondPrecision()
System.ExceptionGetHttpStatusCode()SetHttpStatusCode()
System.IO.StreamToByteArray()ToByteArrayAsync()TryResetStreamPosition()
System.Reflection.AssemblySystem.Reflection.MemberInfoSystem.Reflection.ParameterInfoSystem.StringIsNullOrEmpty()IsNullOrWhiteSpace()DefaultIfNullOrEmpty()DefaultIfNullOrWhiteSpace()EnsureTrailingSlash()EnsureNoTrailingSlash()
System.TypeAsNullableValueType()IsNullableValueType()
- 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.DecimalIsZero()IsNegative()IsNegativeOrZero()IsPositive()IsPositiveOrZero()IsInRange()
IEnumerable-relatedAsSingleElementSequence()IsIn()IsNotIn()
Reflection-relatedGetPropertyValue()TryPropertyValue()SetPropertyValue()TrySetPropertyValue()
- value selectors
GetStringValueOrNull()GetStringValueOrEmptyString()GetValueOrDefault()GetValue()
CharsDateTimeFormatsGenericTypeDefinitionsGuidFormatsHttpStatusCodesStrings
IntervalBoundsOptions- can be used in the newIsInRange()extension methods.
EnumInfo<TEnum>- A wrapper class that provides additional information about an
enumtype or value.- The custom attributes applied to a member.
- Easy access to the list of the defined members.
- Easy access to the name or the underlying value of a member.
- Support for customizing the serialized value through attributes.
- Implements bitwise / comparison / implicit conversion / equality operators.
- A wrapper class that provides additional information about an
EncodingProviderUTF8WithoutBOMThe UTF-8 encoding without the Unicode byte order mark.
StringSyntaxAttribute- up to .NET 6 (This attribute is part of .NET 7+.)
StructuralEqualityComparer<T>- Provides a generic
IEqualityComparer<T>instance for using the non-genericSystem.Collections.StructuralComparisons.StructuralEqualityComparer.
- Provides a generic
TypeHelperGetName<T>()/GetName(Type)methods as a shortcut forType.FullName ?? Type.Nameexpression.
Learn more at https://github.com/gcsizmadia/EgonsoftHU.Extensions.Bcl