Repository navigation
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.0tonet7.0for 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
messageparameter 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 NewRegexfactory method moved toRegexFactoryclass.
Breaking Changes
- The
parameterNameparameter of all guard clauses was moved to the end to compliance with this sonar analyzer rule. - The
NotExistsguard clause now includes theparameterNamevalue in it's exception message. - The
InvalidEmailguard clause now thows anArgumentExceptioninstead ofFormatExceptionto includes theparameterNamevalue in it's exception message. - The
Emailvalue object now thows anArgumentExceptioninstead ofFormatExceptionto includes theparameterNamevalue 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