Skip to content

Extending the platform family, fast!

Compare
Choose a tag to compare
@feO2x feO2x released this 10 Jul 21:25

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.