FlagProvider 1.0.0

dotnet add package FlagProvider --version 1.0.0
                    
NuGet\Install-Package FlagProvider -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="FlagProvider" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="FlagProvider" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="FlagProvider" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add FlagProvider --version 1.0.0
                    
#r "nuget: FlagProvider, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package FlagProvider@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=FlagProvider&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=FlagProvider&version=1.0.0
                    
Install as a Cake Tool

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, and germany will all work.
Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • 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