Skip to content

gcsizmadia/EgonsoftHU.Extensions.Bcl

Repository files navigation

Egonsoft.HU BCL Extensions

GitHub Nuget Nuget

C# extension methods for Base Class Library types.

Introduction

The motivation behind this project is to collect reusable extension methods into a NuGet package avoiding CPD (copy-paste-development).

Documentation

You can find the complete documentation here.

The documentation is generated by Sandcastle Help File Builder.

Releases

You can download the package from nuget.org.

You can find the release notes here.

Package Contents

There are examples below only for some of the methods. Feel free to discover all the methods in the documentation.

Extension methods for throwing ArgumentNullException

  • ThrowExtensions (examples)
    • T generic type: null
    • string: null, String.Empty or white-space only
    • Guid: Guid.Empty

Extension methods for throwing ArgumentOutOfRangeException

  • 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"
      );
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()

Extension methods for the following types

  • 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

Other extension methods with generic type parameters

  • IEnumerable-related (examples)
  • Reflection-related
  • value selectors

Predefined (const / readonly) values

  • GuidFormat (examples)
  • GenericTypeDefinitions