5.0.0
New Features
Package: Krafted.Guards
The parameterName
parameter is no longer required thanks the CallerArgumentExpression
attribute (C# 10).
So instead of do this:
return Guard.Against
.Null(name, nameof(name))
.NullOrWhiteSpace(shortDescription, nameof(shortDescription))
.Length(5, 200, shortDescription, nameof(shortDescription))
.Null(category, nameof(category))
.Null(price, nameof(price));
Now, you just need to do this:
return Guard.Against
.Null(name)
.NullOrWhiteSpace(shortDescription)
.Length(5, 200, shortDescription)
.Null(category)
.Null(price);
Read more about the CallerArgumentExpression
attribute.
Bypass-nullable-types
The parameter
argument, for all the guard clause methods was changed to nullable.
Therefore now if the parameter
argument is null
, the validation is ignored (i.e. does not throw an Exception).
This is useful for optional parameters whose default value is null
.
New Guard Clauses
InvalidCpf(...)
InvalidCnpj(...)
Package: Krafted.UnitTests
New AssertExtension methods to verifies that a type contains (or not) Null Guard Clauses
for all parameters of it constructor.
Assert.ContainsNullGuardClause<T>(...)
Assert.DoesNotContainNullGuardClause<T>(...)
Package: Krafted.Extensions
New extension method
EnumExtension.GetDisplayName(...)
Package: Krafted.ValueObjects
ActivatorHelper.CreateInstance()
method overloaded to support Value Objects with DateTime
.
When using Entity Framework with Lazy Loading, the ActivatorHelper
provides a helper method to bypass the Guard Clauses via reflection, during the Value Object materialization.
Read more
Improvements
-
The target framework moniker (TFM) was changed from
netstandard2.0
tonet7.0
for all projects of solution in order to take the benefits of C# 11 and latest SDK. -
Code cleanup removing all
nameof(param)
for Guard Clauses internal uses; -
Nullable reference type (NRT) enabled for almost all projects of solution;
-
New optional
message
parameter added to all guard clause methods.
If this parameter is provided, it will override the error message described in the summary section. -
Analyzers rulesets replaced for .editorconfig
-
Nuget packages updated.
-
Refactor
- The guard clause methods were cleaned due to the call of the new Validate method;
- Guard clauses classes moved to GuardClauses folder;
internal NewRegex
factory method moved toRegexFactory
class
.
Breaking Changes
- The
parameterName
parameter of all guard clauses was moved to the end to compliance with this sonar analyzer rule. - The
NotExists
guard clause now includes theparameterName
value in it's exception message. - The
InvalidEmail
guard clause now thows anArgumentException
instead ofFormatException
to includes theparameterName
value in it's exception message. - The
Email
value object now thows anArgumentException
instead ofFormatException
to includes theparameterName
value in it's exception message. Guard.Empty<T>()
was renamed toGuard.NotAny<T>()
to fit better with theSystem.Linq.Any()
name;Guard.NotEmpty<T>()
was renamed toGuard.Any<T>()
to fit better with theSystem.Linq.Any()
name;
Full Changelog: v4.2.2...v5.0.0