2023-10-11 22:15:27 +02:00
|
|
|
# Nyanbyte.Countries
|
|
|
|
|
2023-12-24 15:14:17 +01:00
|
|
|
A .NET library for country data, including ISO Codes, currencies, and other data associated with countries.
|
|
|
|
|
|
|
|
## Usage
|
|
|
|
|
|
|
|
### Fixed countries by ISO 3166-1 alpha2 code enums
|
|
|
|
|
|
|
|
```csharp
|
|
|
|
using Nyanbyte.Countries;
|
|
|
|
|
|
|
|
Country pl = CountryCodes.PL.GetCountry();
|
|
|
|
|
|
|
|
// use the object
|
|
|
|
|
|
|
|
Console.WriteLine(pl.OfficialName == "Poland");
|
|
|
|
```
|
|
|
|
|
|
|
|
or
|
|
|
|
|
|
|
|
```csharp
|
|
|
|
using Nyanbyte.Countries;
|
|
|
|
|
|
|
|
Country pl = Country.GetFromCode(CountryCodes.PL);
|
|
|
|
|
|
|
|
// use the object
|
|
|
|
|
|
|
|
Console.WriteLine(pl.OfficialName == "Poland");
|
|
|
|
```
|
|
|
|
|
|
|
|
### Querying by data
|
|
|
|
|
|
|
|
The methods:
|
|
|
|
|
|
|
|
- `GetFromName`
|
|
|
|
- `GetByCurrency(string)`
|
|
|
|
- `GetByCurrency(int)`
|
|
|
|
- `GetFromCallingCode`
|
|
|
|
- `GetFromTld`
|
|
|
|
|
|
|
|
do not guarantee results due to potential invalid input.
|
|
|
|
Therefore validation is required.
|
|
|
|
|
|
|
|
```csharp
|
|
|
|
using Nyanbyte.Countries;
|
|
|
|
|
|
|
|
Country? country = Country.GetFromCallingCode(48);
|
|
|
|
|
|
|
|
if(country is null)
|
|
|
|
{
|
|
|
|
//handle invalid result
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// use the object otherwise
|
|
|
|
Console.WriteLine(pl.OfficialName);
|
|
|
|
```
|