Extending the platform family, fast!
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
andCheck.InvalidState
that throw anInvalidOperationException
orInvalidStateException
, respectively.MustNotBeDefault
asserts that a value is notdefault(T)
.MustNotBeNullReference
is the same asMustNotBeNull
but for generic scenarios whereT
is not contrained to be a reference type.IsValidEnumValue
now supports enums marked with theFlagsAttribute
, 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
andCheck.Against
. - Removed all
DictionaryAssertions
- use the normalEnumerableAssertions
on theKeys
orValues
collection of a dictionary if necessary. - Removed the following assertions because this is not an assertion library for unit testing:
MustBeTrue
andMustBeFalse
MustNotHaveValue
forNullable<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 knownStringComparison
. - The following string assertions were removed:
IsMatching
IsContaining
MustContainOnlyLetters
andContainsOnlyLetters
MustContainOnlyLettersAndDigits
andContainsOnlyLettersAndDigits
MustHaveLengthIn
,MustMotHaveLengthIn
, andIsLengthIn
- Removed extension methods
IndexOf
andIsContaining
forIReadOnlyList<T>
. - Class
Equality
is now calledMultiplyAddHash
, removedEqualsValueWithHashCode
from it. - More fine-grained exception hierarchy.
StringBuilderExtensions
are now calledTextExtensions
, removedAppendDictionaryContent
andAppendKeyValuePair
.- The
Types
class is now in namespaceLight.GuardClauses
, removedMulticastDelegateType
. - All
EqualityAssertions
can now be found inCheck.CommonAssertions.cs
. TypeAssertions
has the following breaking changes:- All assertions that throw exceptions were removed
IsClass
,IsInterface
,IsDelegate
,IsStruct
,IsEnum
,IsReferenceType
,IsValueType
,IsGenericParameter
,IsAbstraction
, andIsStaticClass
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.