Skip to content

Commit

Permalink
fix: no ref in for parse
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasteles committed Dec 28, 2022
1 parent 8acf1de commit 11aabf1
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/BrazilModels.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>
<ItemGroup>
<None Include="..\..\README.md" Pack="true" PackagePath="\"/>
<None Include="..\README.md" Pack="true" PackagePath="\"/>
</ItemGroup>

<PropertyGroup Condition="'$(GITHUB_ACTIONS)' == 'true'">
Expand Down
4 changes: 2 additions & 2 deletions src/Cnpj.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public static explicit operator Cnpj(in string value)
/// <exception cref="ArgumentNullException">
/// Throws a ArgumentNullException if the passed <para name="value" /> is null.
/// </exception>
public static Cnpj Parse(in string value)
public static Cnpj Parse(string value)
{
ArgumentNullException.ThrowIfNull(value);
return !TryParse(value, out var cnpj)
Expand All @@ -133,7 +133,7 @@ public static Cnpj Parse(in string value)
/// contains a valid Cnpj. If the method returns false, result equals Empty.
/// </param>
/// <returns> true if the parse operation was successful; otherwise, false.</returns>
public static bool TryParse(in string value, out Cnpj result)
public static bool TryParse(string value, out Cnpj result)
{
var normalized = Format(value);
if (!Validate(normalized))
Expand Down
4 changes: 2 additions & 2 deletions src/Cpf.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public static explicit operator Cpf(in string value)
/// <exception cref="ArgumentNullException">
/// Throws a ArgumentNullException if the passed <para name="value" /> is null.
/// </exception>
public static Cpf Parse(in string value)
public static Cpf Parse(string value)
{
ArgumentNullException.ThrowIfNull(value);
return !TryParse(value, out var cpf)
Expand All @@ -131,7 +131,7 @@ public static Cpf Parse(in string value)
/// contains a valid Cpf. If the method returns false, result equals Empty.
/// </param>
/// <returns> true if the parse operation was successful; otherwise, false.</returns>
public static bool TryParse(in string value, out Cpf result)
public static bool TryParse(string value, out Cpf result)
{
var normalized = Format(value, withMask: false);
if (!Validate(normalized))
Expand Down
33 changes: 27 additions & 6 deletions src/TaxId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ public TaxId(in ReadOnlySpan<char> value)
/// <returns>Tax Id as string</returns>
public string ToString(bool withMask) => Format(Value, Type, withMask);

static Exception TaxIdException(in ReadOnlySpan<char> value) => new FormatException($"Invalid TaxId: {value}");
static Exception TaxIdException(in ReadOnlySpan<char> value) =>
new FormatException($"Invalid TaxId: {value}");

/// <summary>
/// Convert Tax Id to string representation without mask
Expand All @@ -107,6 +108,22 @@ public TaxId(in ReadOnlySpan<char> value)
/// <returns>Tax Id as string</returns>
public static implicit operator string(in TaxId taxId) => taxId.Value;

/// <summary>
/// Convert Cnpj to TaxId representation without mask
/// </summary>
/// <param name="cnpj">A Tax Id structure</param>
/// <returns>Tax Id as string</returns>
public static implicit operator TaxId(in Cnpj cnpj) => new(cnpj.Value);


/// <summary>
/// Convert Cpf to TaxId representation without mask
/// </summary>
/// <param name="cpf">A Tax Id structure</param>
/// <returns>Tax Id as string</returns>
public static implicit operator TaxId(in Cpf cpf) => new(cpf.Value);


/// <summary>
/// Convert Tax Id to ReadOnlySpan representation without mask
/// </summary>
Expand Down Expand Up @@ -139,7 +156,7 @@ public static explicit operator TaxId(in string value)
/// <exception cref="ArgumentNullException">
/// Throws a ArgumentNullException if the passed <para name="value" /> is null.
/// </exception>
public static TaxId Parse(in string value)
public static TaxId Parse(string value)
{
ArgumentNullException.ThrowIfNull(value);
return new TaxId(value);
Expand All @@ -153,7 +170,7 @@ public static TaxId Parse(in string value)
/// contains a valid TaxId. If the method returns false, result equals Empty.
/// </param>
/// <returns> true if the parse operation was successful; otherwise, false.</returns>
public static bool TryParse(in string value, out TaxId result)
public static bool TryParse(string value, out TaxId result)
{
var type = Validate(value);
if (type is null)
Expand All @@ -167,9 +184,12 @@ public static bool TryParse(in string value, out TaxId result)
}

/// <inheritdoc />
public int CompareTo(TaxId other) => string.Compare(Value, other.Value, StringComparison.OrdinalIgnoreCase);
public int CompareTo(TaxId other) =>
string.Compare(Value, other.Value, StringComparison.OrdinalIgnoreCase);

string DebuggerDisplay() => Value == Empty ? "WARNING: INVALID TAX ID!" : $"Tax Id{{{Format(Value, Type, true)}}}";
string DebuggerDisplay() => Value == Empty
? "WARNING: INVALID TAX ID!"
: $"Tax Id{{{Format(Value, Type, true)}}}";

/// <summary>
/// Validate given TaxId
Expand Down Expand Up @@ -205,7 +225,8 @@ public static string Format(in ReadOnlySpan<char> value, bool withMask = false)
/// <param name="type">TaxId Type</param>
/// <param name="withMask">if true, returns formatted TaxId with mask</param>
/// <returns>Formatted Tax Id string</returns>
public static string Format(in ReadOnlySpan<char> value, TaxIdType? type, bool withMask = false) =>
public static string Format(in ReadOnlySpan<char> value, TaxIdType? type,
bool withMask = false) =>
type switch
{
TaxIdType.CNPJ => Cnpj.Format(value, withMask),
Expand Down

0 comments on commit 11aabf1

Please sign in to comment.