Skip to content

Commit d6720f1

Browse files
author
Bruno de Souza Melo
committed
Full nullable review.
Support .NET 7 removed.
1 parent 4fb1f95 commit d6720f1

15 files changed

+103
-70
lines changed

docs/Publishing.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
nuget.exe push -Source "nuvtools" -ApiKey az NuvTools.Validation.8.0.0.nupkg
1+
nuget.exe push -Source "nuvtools" -ApiKey az NuvTools.Validation.8.1.1.nupkg

src/NuvTools.Validation/Annotations/PasswordComplexityBaseAttribute.cs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,9 @@
44

55
namespace NuvTools.Validation.Annotations;
66

7-
public abstract class PasswordComplexityBaseAttribute : ValidationAttribute
7+
public abstract class PasswordComplexityBaseAttribute(int minOccurrences, Func<string> errorMessageAccessor) : ValidationAttribute(errorMessageAccessor)
88
{
9-
public int MinOccurrences { get; private set; }
10-
11-
public PasswordComplexityBaseAttribute(int minOccurrences, Func<string> errorMessageAccessor)
12-
: base(errorMessageAccessor)
13-
{
14-
MinOccurrences = minOccurrences;
15-
}
9+
public int MinOccurrences { get; private set; } = minOccurrences;
1610

1711
/// <summary>
1812
/// Applies formatting to a specified error message. (Overrides <see cref = "ValidationAttribute.FormatErrorMessage" />)
@@ -36,7 +30,7 @@ protected void EnsureLegalMinOcorrences()
3630
}
3731
}
3832

39-
protected static bool IsValidValue(object value)
33+
protected static bool IsValidValue(object? value)
4034
{
4135
return value != null
4236
&& value is string

src/NuvTools.Validation/Annotations/PasswordComplexityCapitalLettersAttribute.cs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,16 @@
33

44
namespace NuvTools.Validation.Annotations;
55

6-
public class PasswordComplexityCapitalLettersAttribute : PasswordComplexityBaseAttribute
6+
public class PasswordComplexityCapitalLettersAttribute(int minOccurrences) : PasswordComplexityBaseAttribute(minOccurrences, () => Messages.XMustContainAtLeastYCapitalLetters)
77
{
8-
public PasswordComplexityCapitalLettersAttribute(int minOccurrences)
9-
: base(minOccurrences, () => Messages.XMustContainAtLeastYCapitalLetters)
10-
{
11-
}
12-
13-
public override bool IsValid(object value)
8+
public override bool IsValid(object? value)
149
{
1510
EnsureLegalMinOcorrences();
1611

1712
// Automatically pass if value is null. RequiredAttribute should be used to assert a value is not null.
1813
if (!IsValidValue(value)) return true;
1914

20-
string str = value as string;
15+
string str = (string)value!;
2116

2217
return Regex.Matches(str, @"[A-Z]").Count >= MinOccurrences;
2318
}

src/NuvTools.Validation/Annotations/PasswordComplexityDigitsAttribute.cs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,16 @@
33

44
namespace NuvTools.Validation.Annotations;
55

6-
public class PasswordComplexityDigitsAttribute : PasswordComplexityBaseAttribute
6+
public class PasswordComplexityDigitsAttribute(int minOccurrences) : PasswordComplexityBaseAttribute(minOccurrences, () => Messages.XMustContainAtLeastYDigits)
77
{
8-
public PasswordComplexityDigitsAttribute(int minOccurrences)
9-
: base(minOccurrences, () => Messages.XMustContainAtLeastYDigits)
10-
{
11-
}
12-
13-
public override bool IsValid(object value)
8+
public override bool IsValid(object? value)
149
{
1510
EnsureLegalMinOcorrences();
1611

1712
// Automatically pass if value is null. RequiredAttribute should be used to assert a value is not null.
1813
if (!IsValidValue(value)) return true;
1914

20-
string str = value as string;
15+
string str = (string)value!;
2116

2217
return Regex.Matches(str, @"[0-9]").Count >= MinOccurrences;
2318
}

src/NuvTools.Validation/Annotations/PasswordComplexityLowerCaseLettersAttribute.cs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,16 @@
33

44
namespace NuvTools.Validation.Annotations;
55

6-
public class PasswordComplexityLowerCaseLettersAttribute : PasswordComplexityBaseAttribute
6+
public class PasswordComplexityLowerCaseLettersAttribute(int minOccurrences) : PasswordComplexityBaseAttribute(minOccurrences, () => Messages.XMustContainAtLeastYLowerCaseLetters)
77
{
8-
public PasswordComplexityLowerCaseLettersAttribute(int minOccurrences)
9-
: base(minOccurrences, () => Messages.XMustContainAtLeastYLowerCaseLetters)
10-
{
11-
}
12-
13-
public override bool IsValid(object value)
8+
public override bool IsValid(object? value)
149
{
1510
EnsureLegalMinOcorrences();
1611

1712
// Automatically pass if value is null. RequiredAttribute should be used to assert a value is not null.
1813
if (!IsValidValue(value)) return true;
1914

20-
string str = value as string;
15+
string str = (string)value!;
2116

2217
return Regex.Matches(str, @"[a-z]").Count >= MinOccurrences;
2318
}

src/NuvTools.Validation/Annotations/StringValueBaseAttribute.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,8 @@
33

44
namespace NuvTools.Validation.Annotations;
55

6-
public class StringValueBaseAttribute : ValidationAttribute
6+
public class StringValueBaseAttribute(Func<string> errorMessageAccessor) : ValidationAttribute(errorMessageAccessor)
77
{
8-
public StringValueBaseAttribute(Func<string> errorMessageAccessor)
9-
: base(errorMessageAccessor)
10-
{
11-
}
128

139
/// <summary>
1410
/// Applies formatting to a specified error message. (Overrides <see cref = "ValidationAttribute.FormatErrorMessage" />)
@@ -20,7 +16,7 @@ public override string FormatErrorMessage(string name)
2016
return string.Format(CultureInfo.CurrentCulture, ErrorMessageString, name);
2117
}
2218

23-
protected static bool IsValidValue(object value)
19+
protected static bool IsValidValue(object? value)
2420
{
2521
return value != null
2622
&& value is string

src/NuvTools.Validation/Brazil/Annotations/CNPJAttribute.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ public CNPJAttribute()
1010
{
1111
}
1212

13-
public override bool IsValid(object value)
13+
public override bool IsValid(object? value)
1414
{
1515
// Automatically pass if value is null. RequiredAttribute should be used to assert a value is not null.
1616
if (!IsValidValue(value)) return true;
1717

18-
string str = value as string;
18+
string str = (string)value!;
1919

2020
return Validator.IsCNPJ(str);
2121
}

src/NuvTools.Validation/Brazil/Annotations/CPFttribute.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ public CPFAttribute()
1010
{
1111
}
1212

13-
public override bool IsValid(object value)
13+
public override bool IsValid(object? value)
1414
{
1515
// Automatically pass if value is null. RequiredAttribute should be used to assert a value is not null.
1616
if (!IsValidValue(value)) return true;
1717

18-
string str = value as string;
18+
string str = (string)value!;
1919

2020
return Validator.IsCPF(str);
2121
}

src/NuvTools.Validation/Brazil/Validator.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,4 +127,19 @@ public static bool IsMobileNumber(this string mobileNumber, bool clearMask = tru
127127
return match.Success;
128128
}
129129

130+
/// <summary>
131+
/// Validates Zip Code number
132+
/// </summary>
133+
/// <param name="zipCode">Zip Code.</param>
134+
/// <param name="clearMask">Clear mask before validate.</param>
135+
/// <returns></returns>
136+
public static bool IsZipCodeNumber(this string zipCode, bool clearMask = true)
137+
{
138+
zipCode = zipCode.GetNumbersOnly();
139+
140+
if (zipCode.Length != 8) return false;
141+
142+
return true;
143+
}
144+
130145
}

src/NuvTools.Validation/NuvTools.Validation.csproj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>net7;net8</TargetFrameworks>
4+
<TargetFrameworks>net8</TargetFrameworks>
55
<LangVersion>latest</LangVersion>
66
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
77
<Authors>Nuv Tools</Authors>
@@ -10,7 +10,7 @@
1010
<SignAssembly>True</SignAssembly>
1111
<AssemblyOriginatorKeyFile>NuvTools.Validation.snk</AssemblyOriginatorKeyFile>
1212
<Description>Validation library for Web, Desktop and Mobile (MAUI) applications.</Description>
13-
<Version>8.1.0</Version>
13+
<Version>8.1.1</Version>
1414
<GenerateDocumentationFile>True</GenerateDocumentationFile>
1515
<EnforceCodeStyleInBuild>True</EnforceCodeStyleInBuild>
1616
<PackageIcon>icon.png</PackageIcon>
@@ -23,6 +23,7 @@
2323
<PackageReadmeFile>README.md</PackageReadmeFile>
2424
<PackageTags>NuvTools Validators CPF CNPJ</PackageTags>
2525
<ImplicitUsings>true</ImplicitUsings>
26+
<Nullable>enable</Nullable>
2627
</PropertyGroup>
2728

2829
<ItemGroup>

0 commit comments

Comments
 (0)