Releases: feO2x/Light.GuardClauses
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.InvalidOperationandCheck.InvalidStatethat throw anInvalidOperationExceptionorInvalidStateException, respectively.MustNotBeDefaultasserts that a value is notdefault(T).MustNotBeNullReferenceis the same asMustNotBeNullbut for generic scenarios whereTis not contrained to be a reference type.IsValidEnumValuenow supports enums marked with theFlagsAttribute, too.
Breaking Changes:
- All assertions are now in the static
Checkclass. - All assertions that throw exceptions were split into two overloads: one throwing the default exception, and one where a custom delegate
exceptionFactoryis provided. - Removed
Check.ThatandCheck.Against. - Removed all
DictionaryAssertions- use the normalEnumerableAssertionson theKeysorValuescollection of a dictionary if necessary. - Removed the following assertions because this is not an assertion library for unit testing:
MustBeTrueandMustBeFalseMustNotHaveValueforNullable<T>- Collection assertions:
IsContainingDuplicatesMustNotContainDuplicatesMustNotContainNullMustBeSubsetOfIsSubsetOfMustContainInstancesOfDifferentTypesIsContainingInstancesOfDifferentTypesMustStartWithIsStartingWithMustEndWithIsEndingWithMustNotStartWithMustNotEndWithMustStartWithEquivalentOfMustNotStartWithEquivalentOfMustEndWithEquivalentOfMustNotEndWithEquivalentOfIsStructurallyEqualToIsStructurallyEquivalentTo
- Removed
IngoreCaseInfoand corresponding assertions for strings, instead overloads were added that use the well knownStringComparison. - The following string assertions were removed:
IsMatchingIsContainingMustContainOnlyLettersandContainsOnlyLettersMustContainOnlyLettersAndDigitsandContainsOnlyLettersAndDigitsMustHaveLengthIn,MustMotHaveLengthIn, andIsLengthIn
- Removed extension methods
IndexOfandIsContainingforIReadOnlyList<T>. - Class
Equalityis now calledMultiplyAddHash, removedEqualsValueWithHashCodefrom it. - More fine-grained exception hierarchy.
StringBuilderExtensionsare now calledTextExtensions, removedAppendDictionaryContentandAppendKeyValuePair.- The
Typesclass is now in namespaceLight.GuardClauses, removedMulticastDelegateType. - All
EqualityAssertionscan now be found inCheck.CommonAssertions.cs. TypeAssertionshas the following breaking changes:- All assertions that throw exceptions were removed
IsClass,IsInterface,IsDelegate,IsStruct,IsEnum,IsReferenceType,IsValueType,IsGenericParameter,IsAbstraction, andIsStaticClasswere removed- Generally, everything in the context of
TypeInfowas removed. The traditional reflection model already provides the members that achieve most of the goals -TypeInfois 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
New Features in version 3.5.0
- added structural equality testing for collections:
IsStructurallyEquivalentToandIsStructurallyEqualTo - added overloads for
AsListandAsReadOnlyListthat allow you to specify a create-collection-delegate - added
IndexOfandIsContainingforIReadOnlyList<T>
Wait, these are no assertions
New Features in version 3.4.0
- added
ExtractProperyandExtractFieldfor Expressions
Of Static Classes and String Lengths
New Features in version 3.3.0
- added
IsStaticClass,MustBeStaticClass, andMustNotBeStaticClassfor Types - added
MustHaveMinimumLengthandMustHaveMaximumLengthfor Strings - added
IsLengthIn,MustHaveLengthIn, andMustNotHaveLengthInfor Strings
Abstraction, please!
New Features in version 3.2.0
- added
MustBeAbstractionandIsAbstractionfor types - added
IsMatchingfor strings - added
ForEachandIsOneOffor enumerables
Reflected, Generically
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
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!
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?
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
Equality.CreateHashCode now won't throw an exception when one of the passed in values is null.