-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce SwedishPersonalIdentityNumber (#6)
- SwedishPersonalNumber is now discontinued
- Loading branch information
Showing
17 changed files
with
566 additions
and
421 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
src/SwedishPersonalIdentityNumber/SwedishPersonalIdentityNumber.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFrameworks>net5.0;netstandard2.1</TargetFrameworks> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup> | ||
<PackageDescription>This package contains a representation of the Swedish Personal Identity Number that can be reused across projects. It supports parsing a string and printing it as a string according to different formats.</PackageDescription> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<Compile Update="SwedishPersonalIdentityNumber.*.cs"> | ||
<DependentUpon>SwedishPersonalIdentityNumber.cs</DependentUpon> | ||
</Compile> | ||
</ItemGroup> | ||
|
||
</Project> |
38 changes: 38 additions & 0 deletions
38
src/SwedishPersonalIdentityNumber/SwedishPersonalIdentityNumberFormats.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
namespace InsightArchitectures.Types | ||
{ | ||
/// <summary> | ||
/// A set of formats that can be used to represent a Swedish Personal Identity Number. | ||
/// </summary> | ||
public static class SwedishPersonalIdentityNumberFormats | ||
{ | ||
/// <summary> | ||
/// A formatter that formats a <see cref="SwedishPersonalIdentityNumber" /> using the formatter <c>yyyyMMdd-xxxx</c>. | ||
/// </summary> | ||
public static readonly SwedishPersonalIdentityNumberFormatter TwelveDigits = new TwelveDigitsSwedishPersonalIdentityNumberFormatter(); | ||
|
||
/// <summary> | ||
/// A formatter that formats a <see cref="SwedishPersonalIdentityNumber" /> using the formatter <c>yyMMdd-xxxx</c>. | ||
/// </summary> | ||
public static readonly SwedishPersonalIdentityNumberFormatter TenDigits = new TenDigitsSwedishPersonalIdentityNumberFormatter(); | ||
|
||
/// <summary> | ||
/// A formatter that formats a <see cref="SwedishPersonalIdentityNumber" /> using the formatter <c>yyyyMMddxxxx</c>. | ||
/// </summary> | ||
public static readonly SwedishPersonalIdentityNumberFormatter NoSplitTwelveDigits = new NoSplitTwelveDigitsSwedishPersonalIdentityNumberFormatter(); | ||
|
||
/// <summary> | ||
/// A formatter that formats a <see cref="SwedishPersonalIdentityNumber" /> using the formatter <c>yyMMddxxxx</c>. | ||
/// </summary> | ||
public static readonly SwedishPersonalIdentityNumberFormatter NoSplitTenDigits = new NoSplitTenDigitsSwedishPersonalIdentityNumberFormatter(); | ||
|
||
/// <summary> | ||
/// A formatter that formats a <see cref="SwedishPersonalIdentityNumber" /> using the formatter <c>yyyy-MM-dd-xxxx</c>. | ||
/// </summary> | ||
public static readonly SwedishPersonalIdentityNumberFormatter SplitTwelveDigits = new SplitTwelveDigitsSwedishPersonalIdentityNumberFormatter(); | ||
|
||
/// <summary> | ||
/// A formatter that formats a <see cref="SwedishPersonalIdentityNumber" /> using the formatter <c>yy-MM-dd-xxxx</c>. | ||
/// </summary> | ||
public static readonly SwedishPersonalIdentityNumberFormatter SplitTenDigits = new SplitTenDigitsSwedishPersonalIdentityNumberFormatter(); | ||
} | ||
} |
101 changes: 101 additions & 0 deletions
101
src/SwedishPersonalIdentityNumber/SwedishPersonalIdentityNumberFormatter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
using System; | ||
|
||
namespace InsightArchitectures.Types | ||
{ | ||
/// <summary> | ||
/// An abstract class that represents the different ways to formatter a Swedish personal identity number as a string. | ||
/// </summary> | ||
public abstract class SwedishPersonalIdentityNumberFormatter | ||
{ | ||
/// <summary> | ||
/// Formats the <paramref name="pin"/> according to the specified concrete implementation. | ||
/// </summary> | ||
/// <param name="pin">The Swedish personal identity number to formatter as string.</param> | ||
/// <returns>The string formatted according to the concrete implementation.</returns> | ||
public abstract string Format(SwedishPersonalIdentityNumber pin); | ||
} | ||
|
||
/// <summary> | ||
/// Formats a Swedish personal identity number using the formatter yyyyMMddxxxx. | ||
/// </summary> | ||
public class NoSplitTwelveDigitsSwedishPersonalIdentityNumberFormatter : SwedishPersonalIdentityNumberFormatter | ||
{ | ||
/// <inheritdoc/> | ||
public override string Format(SwedishPersonalIdentityNumber pn) | ||
{ | ||
_ = pn ?? throw new ArgumentNullException(nameof(pn)); | ||
|
||
return $"{pn.DateOfBirth:yyyyMMdd}{pn.OrdinalNumber:0000}"; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Formats a Swedish personal identity number using the formatter yyMMddxxxx. | ||
/// </summary> | ||
public class NoSplitTenDigitsSwedishPersonalIdentityNumberFormatter : SwedishPersonalIdentityNumberFormatter | ||
{ | ||
/// <inheritdoc/> | ||
public override string Format(SwedishPersonalIdentityNumber pn) | ||
{ | ||
_ = pn ?? throw new ArgumentNullException(nameof(pn)); | ||
|
||
return $"{pn.DateOfBirth:yyMMdd}{pn.OrdinalNumber:0000}"; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Formats a Swedish personal identity number using the formatter yyyyMMdd-xxxx. | ||
/// </summary> | ||
public class TwelveDigitsSwedishPersonalIdentityNumberFormatter : SwedishPersonalIdentityNumberFormatter | ||
{ | ||
/// <inheritdoc/> | ||
public override string Format(SwedishPersonalIdentityNumber pn) | ||
{ | ||
_ = pn ?? throw new ArgumentNullException(nameof(pn)); | ||
|
||
return $"{pn.DateOfBirth:yyyyMMdd}-{pn.OrdinalNumber:0000}"; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Formats a Swedish personal identity number using the formatter yyMMdd-xxxx. | ||
/// </summary> | ||
public class TenDigitsSwedishPersonalIdentityNumberFormatter : SwedishPersonalIdentityNumberFormatter | ||
{ | ||
/// <inheritdoc/> | ||
public override string Format(SwedishPersonalIdentityNumber pn) | ||
{ | ||
_ = pn ?? throw new ArgumentNullException(nameof(pn)); | ||
|
||
return $"{pn.DateOfBirth:yyMMdd}-{pn.OrdinalNumber:0000}"; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Formats a Swedish personal identity number using the formatter yyyyMMdd-xxxx. | ||
/// </summary> | ||
public class SplitTwelveDigitsSwedishPersonalIdentityNumberFormatter : SwedishPersonalIdentityNumberFormatter | ||
{ | ||
/// <inheritdoc/> | ||
public override string Format(SwedishPersonalIdentityNumber pn) | ||
{ | ||
_ = pn ?? throw new ArgumentNullException(nameof(pn)); | ||
|
||
return $"{pn.DateOfBirth:yyyy-MM-dd}-{pn.OrdinalNumber:0000}"; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Formats a Swedish personal identity number using the formatter yyMMdd-xxxx. | ||
/// </summary> | ||
public class SplitTenDigitsSwedishPersonalIdentityNumberFormatter : SwedishPersonalIdentityNumberFormatter | ||
{ | ||
/// <inheritdoc/> | ||
public override string Format(SwedishPersonalIdentityNumber pn) | ||
{ | ||
_ = pn ?? throw new ArgumentNullException(nameof(pn)); | ||
|
||
return $"{pn.DateOfBirth:yy-MM-dd}-{pn.OrdinalNumber:0000}"; | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.