Skip to content

5.0.0

Compare
Choose a tag to compare
@maiconheck maiconheck released this 08 Dec 18:14
· 2 commits to master since this release

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 to net7.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 to RegexFactory class.

Breaking Changes

  • The parameterNameparameter of all guard clauses was moved to the end to compliance with this sonar analyzer rule.
  • The NotExists guard clause now includes the parameterName value in it's exception message.
  • The InvalidEmail guard clause now thows an ArgumentExceptioninstead of FormatException to includes the parameterName value in it's exception message.
  • The Email value object now thows an ArgumentExceptioninstead of FormatException to includes the parameterName value in it's exception message.
  • Guard.Empty<T>() was renamed to Guard.NotAny<T>() to fit better with the System.Linq.Any() name;
  • Guard.NotEmpty<T>() was renamed to Guard.Any<T>() to fit better with the System.Linq.Any() name;

Full Changelog: v4.2.2...v5.0.0