C# extension methods for BCL types (String, Type, etc.)
$ dotnet add package EgonsoftHU.Extensions.BclC# extension methods for Base Class Library types.
ArgumentNullExceptionArgumentExceptionArgumentOutOfRangeExceptionconst / readonly) valuesArgumentNullException or ArgumentExceptionT type:
ThrowIfNull<T>() throws ArgumentNullExceptionSystem.String type:
ThrowIfNullOrEmpty() throws ArgumentNullException or ArgumentExceptionThrowIfNullOrWhiteSpace() throws ArgumentNullException or ArgumentExceptionSystem.Guid type:
ThrowIfEmptyGuid() throws ArgumentExceptionArgumentOutOfRangeExceptionWould 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.
IEquatable<T> type:
ThrowIfEqualTo()ThrowIfNotEqualTo()IComparable<T> type:
ThrowIfLessThan()ThrowIfLessThanOrEqualTo()ThrowIfGreaterThanThrowIfGreaterThanOrEqualTo()System.SByte, System.Int16, System.Int32, System.Int64,System.Byte, System.UInt16, System.UInt32, System.UInt64,System.Half, System.Single, System.Double, System.Decimal
ThrowIfZero()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.DateOnly
IsInRange()System.DateTime
IsInRange()ToMinutePrecision()ToSecondPrecision()System.DateTimeOffset
IsInRange()ToMinutePrecision()ToSecondPrecision()System.Exception
GetHttpStatusCode()SetHttpStatusCode()System.IO.Stream
ToByteArray()ToByteArrayAsync()TryResetStreamPosition()System.Reflection.AssemblySystem.Reflection.MemberInfoSystem.Reflection.ParameterInfoSystem.String
IsNullOrEmpty()IsNullOrWhiteSpace()DefaultIfNullOrEmpty()DefaultIfNullOrWhiteSpace()EnsureTrailingSlash()EnsureNoTrailingSlash()System.Type
AsNullableValueType()IsNullableValueType()System.SByte, System.Int16, System.Int32, System.Int64,System.Byte, System.UInt16, System.UInt32, System.UInt64,System.Half, System.Single, System.Double, System.Decimal
IsZero()IsNegative()IsNegativeOrZero()IsPositive()IsPositiveOrZero()IsInRange()IEnumerable-related
AsSingleElementSequence()IsIn()IsNotIn()Reflection-related
GetPropertyValue()TryPropertyValue()SetPropertyValue()TrySetPropertyValue()GetStringValueOrNull()GetStringValueOrEmptyString()GetValueOrDefault()GetValue()const / readonly) valuesCharsDateTimeFormatsGenericTypeDefinitionsGuidFormatsHttpStatusCodesStringsenum typesIntervalBoundsOptions - can be used in the new IsInRange() extension methods.EnumInfo<TEnum>
enum type or value.
EncodingProvider
UTF8WithoutBOM The UTF-8 encoding without the Unicode byte order mark.StringSyntaxAttribute
StructuralEqualityComparer<T>
IEqualityComparer<T> instance for using the non-generic System.Collections.StructuralComparisons.StructuralEqualityComparer.TypeHelper
GetName<T>() / GetName(Type) methods as a shortcut for Type.FullName ?? Type.Name expression.Learn more at https://github.com/gcsizmadia/EgonsoftHU.Extensions.Bcl