FlagProvider 1.0.0
dotnet add package FlagProvider --version 1.0.0
NuGet\Install-Package FlagProvider -Version 1.0.0
<PackageReference Include="FlagProvider" Version="1.0.0" />
<PackageVersion Include="FlagProvider" Version="1.0.0" />
<PackageReference Include="FlagProvider" />
paket add FlagProvider --version 1.0.0
#r "nuget: FlagProvider, 1.0.0"
#:package FlagProvider@1.0.0
#addin nuget:?package=FlagProvider&version=1.0.0
#tool nuget:?package=FlagProvider&version=1.0.0
FlagProvider
FlagProvider is a .NET library that provides country flag SVGs based on ISO 3166-1 alpha-2 country codes and full country names. This library allows developers to dynamically fetch SVG flag images for various countries in their .NET applications.
Installation
To install FlagProvider, you can use the .NET CLI:
dotnet add package FlagProvider --version 1.0.0
Or, with the NuGet Package Manager:
Install-Package FlagProvider -Version 1.0.0
Usage
Basic Example
FlagProvider allows you to retrieve the path to flag SVGs based on either ISO 3166-1 alpha-2 country codes or full country names, and it's case-insensitive.
using FlagProvider;
class Program
{
static void Main()
{
// Retrieve the flag path by country code
string usFlag = Flag.GetFlag("US"); // Returns path to the US flag
// Retrieve the flag path by country name
string germanyFlag = Flag.GetFlag("Germany"); // Returns path to the Germany flag
Console.WriteLine(usFlag); // Output example: "wwwroot/flags/us.svg"
Console.WriteLine(germanyFlag); // Output example: "wwwroot/flags/de.svg"
}
}
Integration in Blazor
In a Blazor component, you can use FlagProvider
to dynamically load flag images based on a user's selection.
@page "/flags"
@using FlagProvider
<h3>Country Flags</h3>
<img src="@Flag.GetFlag("US")" alt="US Flag" style="width: 40px;" />
<img src="@Flag.GetFlag("Germany")" alt="Germany Flag" style="width: 40px;" />
Methods
Flag.GetFlag(string input)
: Accepts either the ISO country code or the full country name and returns the path to the corresponding SVG flag file.
File Structure and Requirements
- Flag SVGs: Make sure all flag SVGs are located in the
wwwroot/flags
folder. Each flag should be named according to the ISO 3166-1 alpha-2 code (e.g.,us.svg
for the United States,de.svg
for Germany). - Case Insensitivity: The library is case-insensitive, so
US
,us
,Germany
, andgermany
will all work.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.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.
Version | Downloads | Last Updated |
---|---|---|
1.0.0 | 134 | 10/25/2024 |