SwedishIdentityNumbers 1.0.3
dotnet add package SwedishIdentityNumbers --version 1.0.3
NuGet\Install-Package SwedishIdentityNumbers -Version 1.0.3
<PackageReference Include="SwedishIdentityNumbers" Version="1.0.3" />
paket add SwedishIdentityNumbers --version 1.0.3
#r "nuget: SwedishIdentityNumbers, 1.0.3"
// Install SwedishIdentityNumbers as a Cake Addin #addin nuget:?package=SwedishIdentityNumbers&version=1.0.3 // Install SwedishIdentityNumbers as a Cake Tool #tool nuget:?package=SwedishIdentityNumbers&version=1.0.3
SwedishIdentityNumbers
A .NET library for working with Swedish identity numbers.
Overview
The SwedishIdentityNumbers
library provides a set of classes for working with Swedish identity numbers:
Personnummer
for personal identity numbersSamordningsnummer
for coordination numbersOrganisationsnummer
for organization numbers
Each of these classes inherits from the abstract base class SwedishIdentityNumber
, which provides common functionality for validating and working with identity numbers.
Installation
Install SwedishIdentityNumbers
via NuGet:
dotnet add package SwedishIdentityNumbers
Or search for SwedishIdentityNumbers
in the NuGet package manager in Visual Studio.
Usage
Create a Personnummer
using SwedishIdentityNumbers;
var personnummer = new Personnummer("8507301234"); // also allows 850730-1234
// throws
// ArgumentNullException if null
// ArgumentException if empty
// FormatException if not of the correct format
Get the Date of Birth (a DateOnly) from a Personnummer
var dateOfBirth = personnummer.DateOfBirth;
Try to create a Personnummer
using SwedishIdentityNumbers;
if (Personnummer.TryCreate("8507301234", out var personnummer)) // also allows 850730-1234
{
// Successfully created
}
Create a Samordningsnummer
using SwedishIdentityNumbers;
var samordningsnummer = new Samordningsnummer("8507901234"); // also allows 850790-1234
// throws
// ArgumentNullException if null
// ArgumentException if empty
// FormatException if not of the correct format
Get the Date of Birth (a DateOnly) from a Samordningsnummer
var dateOfBirth = samordningsnummer.DateOfBirth;
Working with Organisationsnummer
using SwedishIdentityNumbers;
var organisationsnummer = new Organisationsnummer("5560360793"); // also allows 165560360793 and 556036-0793
// throws
// ArgumentNullException if null
// ArgumentException if empty
// FormatException if not of the correct format
Determine the Probable Swedish Company Form
var companyForm = organisationsnummer.ProbableSwedishCompanyForm;
Swedish Company Forms
The library includes a SwedishCompanyForm
enum, representing different forms of companies in Sweden. This enum is used in conjunction with the Organisationsnummer
class to identify the probable form of a company based on its organization number. The different enum values represent various types of company forms, ranging from Joint Stock Companies to Government Agencies. The implementation and enum values are based on information from Bolagsverket.
public enum SwedishCompanyForm
{
JointStockCompany, // Aktiebolag, filialer, banker, f�rs�kringsbolag och europabolag
GeneralPartnership, // Handelsbolag och kommanditbolag
HousingCooperative, // Bostadsr�ttsf�reningar, ekonomiska f�reningar, etc.
ReligiousCommunity, // Trossamfund
GovernmentAgency, // Statlig myndighet
Unknown // Ok�nd
}
Development
To work on SwedishIdentityNumbers
, clone the repo and open SwedishIdentityNumbers.sln
in Visual Studio or your preferred editor.
Testing
Run the tests in SwedishIdentityNumbers.Tests
to ensure everything is working correctly.
License
SwedishIdentityNumbers
is licensed under the MIT License. See the LICENSE file for details.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net7.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Changed from a FormatException to a ValidationException if check digit is wrong.