Skip to content

Releases: feO2x/Light.GuardClauses

Extending the platform family, fast!

10 Jul 21:25

Choose a tag to compare

Light.GuardClauses 4.0

Important note: there are a lot of breaking changes in between version 3.5 and 4.0 - mainly because a lot of assertions were removed. If you are missing a particular assertion and think it should come back, please open an issue and let me know.

New Features:

  • Support for .NET Standard 2.0 and 1.0, .NET 4.5, .NET 4.0, .NET 3.5 and .NET 3.5 Compact Framework, as well as Silverlight 5 - thanks to @onovotny for his awesome MSBuildSdkExtras.
  • performance improvements across the board - thanks to @redknightlois for his consulting and @AndreyAkinshin and @adamsitnik for their awesome tool Benchmark.NET, many assertions are now about as fast as your imperative code (benchmarks performed in .NET 4.7.x and .NET Core 2.x).
  • ReSharper support via Contract Annotations - ReSharper now understands when Light.GuardClauses assertions do not return a null value and thus removes squiggly lines indicating a possible NullReferenceException.
  • Collection assertions are way faster now, do not allocate, and the returned value actually is of the same collection type that was passed in.
  • New assertions and functionality:
    • Check.InvalidOperation and Check.InvalidState that throw an InvalidOperationException or InvalidStateException, respectively.
    • MustNotBeDefault asserts that a value is not default(T).
    • MustNotBeNullReference is the same as MustNotBeNull but for generic scenarios where T is not contrained to be a reference type.
    • IsValidEnumValue now supports enums marked with the FlagsAttribute, too.

Breaking Changes:

  • All assertions are now in the static Check class.
  • All assertions that throw exceptions were split into two overloads: one throwing the default exception, and one where a custom delegate exceptionFactory is provided.
  • Removed Check.That and Check.Against.
  • Removed all DictionaryAssertions - use the normal EnumerableAssertions on the Keys or Values collection of a dictionary if necessary.
  • Removed the following assertions because this is not an assertion library for unit testing:
    • MustBeTrue and MustBeFalse
    • MustNotHaveValue for Nullable<T>
    • Collection assertions:
      • IsContainingDuplicates
      • MustNotContainDuplicates
      • MustNotContainNull
      • MustBeSubsetOf
      • IsSubsetOf
      • MustContainInstancesOfDifferentTypes
      • IsContainingInstancesOfDifferentTypes
      • MustStartWith
      • IsStartingWith
      • MustEndWith
      • IsEndingWith
      • MustNotStartWith
      • MustNotEndWith
      • MustStartWithEquivalentOf
      • MustNotStartWithEquivalentOf
      • MustEndWithEquivalentOf
      • MustNotEndWithEquivalentOf
      • IsStructurallyEqualTo
      • IsStructurallyEquivalentTo
  • Removed IngoreCaseInfo and corresponding assertions for strings, instead overloads were added that use the well known StringComparison.
  • The following string assertions were removed:
    • IsMatching
    • IsContaining
    • MustContainOnlyLetters and ContainsOnlyLetters
    • MustContainOnlyLettersAndDigits and ContainsOnlyLettersAndDigits
    • MustHaveLengthIn, MustMotHaveLengthIn, and IsLengthIn
  • Removed extension methods IndexOf and IsContaining for IReadOnlyList<T>.
  • Class Equality is now called MultiplyAddHash, removed EqualsValueWithHashCode from it.
  • More fine-grained exception hierarchy.
  • StringBuilderExtensions are now called TextExtensions, removed AppendDictionaryContent and AppendKeyValuePair.
  • The Types class is now in namespace Light.GuardClauses, removed MulticastDelegateType.
  • All EqualityAssertions can now be found in Check.CommonAssertions.cs.
  • TypeAssertions has the following breaking changes:
    • All assertions that throw exceptions were removed
    • IsClass, IsInterface, IsDelegate, IsStruct, IsEnum, IsReferenceType, IsValueType, IsGenericParameter, IsAbstraction, and IsStaticClass were removed
    • Generally, everything in the context of TypeInfo was removed. The traditional reflection model already provides the members that achieve most of the goals - TypeInfo is regarded as obsolete since .NET Standard 2.0.
  • Removed NotNull<T> because when used as a parameter, you cannot be sure that it wasn't created using the default struct initializer.

Some Love for Collections

03 Sep 06:17

Choose a tag to compare

New Features in version 3.5.0

  • added structural equality testing for collections: IsStructurallyEquivalentTo and IsStructurallyEqualTo
  • added overloads for AsList and AsReadOnlyList that allow you to specify a create-collection-delegate
  • added IndexOf and IsContaining for IReadOnlyList<T>

Wait, these are no assertions

27 Aug 19:17

Choose a tag to compare

New Features in version 3.4.0

  • added ExtractPropery and ExtractField for Expressions

Of Static Classes and String Lengths

15 Aug 20:37

Choose a tag to compare

New Features in version 3.3.0

  • added IsStaticClass, MustBeStaticClass, and MustNotBeStaticClass for Types
  • added MustHaveMinimumLength and MustHaveMaximumLength for Strings
  • added IsLengthIn, MustHaveLengthIn, and MustNotHaveLengthIn for Strings

Abstraction, please!

14 Aug 05:53

Choose a tag to compare

New Features in version 3.2.0

  • added MustBeAbstraction and IsAbstraction for types
  • added IsMatching for strings
  • added ForEach and IsOneOf for enumerables

Reflected, Generically

06 Aug 08:51

Choose a tag to compare

New Features in version 3.1.0

Added assertion methods for generic types:

  • IsClosedConstructedGenericType
  • IsOpenConstructedGenericType
  • IsGenericTypeDefinition
  • IsGenericParameterType

Added boolean assertion methods:

  • MustNotBeTrue
  • MustNotBeFalse

Added more variants of existing assertion methods throwing no exception:

  • IsStartingWith and IsEndingWith
  • IsContainingDuplicates
  • IsSubsetOf

Reflected

23 Jul 18:27

Choose a tag to compare

New Features in version 3.0.0

New assertions for Type and TypeInfo:

  • IsEquivalentTo, MustBeEquivalentTo, and MustNotBeEquivalentTo
  • IsClass, MustBeClass, and MustNotBeClass
  • IsInterface, MustBeInterface and MustNotBeInterface
  • IsStruct, MustBeStruct and MustNotBeStruct
  • IsDelegate, MustBeDelegate and MustNotBeDelegate
  • IsEnum, MustBeEnum and MustNotBeEnum
  • IsReferenceType, IsValueType, MustBeReferenceType, and MustBeValueType
  • IsDerivingFrom, IsImplementing, MustDeriveFrom, MustNotDeriveFrom, MustImplement, MustNotImplement, MustDeriveFromOrImplement, MustNotDeriveFromOrImplement
  • IsOrImplements, IsOrDerivesFrom, and IsInInheritanceHierarchyOf

New assertions for strings:

  • IsEquivalentTo, MustBeEquivalentTo, MustNotBeEquivalentTo
  • IsContaining

GetAllExceptionMessages and AppendExceptionMessages can be used to append all exception message into one string.

Breaking Changes:

The API of StringAssertions has changed as MustContain, MustNotContain, MustBeSubstringOf, and MustNotBeSubstringOf were reimplemented to search more efficiently for substring (no additional string creation when case sensitivity is turned off). MustNotBeNullOrEmpty and MustNotBeNullOrWhiteSpace now always throw ArgumentNullExceptions, even when a custom exception is provided.

The second parameter of Check.That and Check.Against is now called exception instead of createException.

.NET Standardized!

30 May 14:14

Choose a tag to compare

Light.GuardClauses is now a .NET Standard 1.0 library.

Breaking Changes:

  • no more conditional compilation: all assertion methods now return the value that they check, so that they can be easily chained or set on a field. COMPILE_ASSERTIONS is gone.
  • Equality now only depends on IEqualityComparer. There are no assertions that directly address IEquatable or struct comparison. Just use MustBe or MustNotBe and optionally pass in an IEqualityComparer instance. This also affects most EnumerableAssertions.

Added features:

  • new assertions for URIs: MustHaveOneSchemeOf, MustBeHttpUrl, MustBeHttpsUrl, and MustBeHttpOrHttpsUrl
  • AsReadOnlyList takes an IEnumerable and tries to cast it to an IReadOnlyList instance. If that is not possible, a new List instance with the items of the enumerable will be returned.

Assertions without exceptions? Really?

12 Apr 05:34

Choose a tag to compare

New assertion methods for DateTime: MustBeUtc, MustBeLocal, and MustBeUnspecified.
New assertion methods for Uri: MustBeAbsoluteUri, and MustHaveScheme

New assertion methods that won't throw exceptions:

  • IsValidEnumValue,
  • IsEmpty (for GUIDs),
  • IsIn and IsNotIn (ranges),
  • IsNullOrEmpty (for collections and strings)
  • IsNullOrWhiteSpace (for strings)
  • IsSameAs (for object references)
  • ContainsOnlyLetters and ContainsOnlyLettersAndDigits (for strings)

CreateHashCode with Null

16 Nov 19:41

Choose a tag to compare

Equality.CreateHashCode now won't throw an exception when one of the passed in values is null.