| | | 1 | | // ----------------------------------------------------------------------- |
| | | 2 | | // <copyright file="CountryExtensions.cs" company="Stéphane ANDRE"> |
| | | 3 | | // Copyright (c) Stéphane ANDRE. All rights reserved. |
| | | 4 | | // </copyright> |
| | | 5 | | // ----------------------------------------------------------------------- |
| | | 6 | | |
| | | 7 | | using System; |
| | | 8 | | using System.IO; |
| | | 9 | | |
| | | 10 | | #pragma warning disable IDE0130 // Namespace does not match folder structure |
| | | 11 | | namespace MyNet.Geography; |
| | | 12 | | #pragma warning restore IDE0130 // Namespace does not match folder structure |
| | | 13 | | |
| | | 14 | | public static class CountryExtensions |
| | | 15 | | { |
| | | 16 | | extension(Country country) |
| | | 17 | | { |
| | | 18 | | /// <summary> |
| | | 19 | | /// Retrieves the flag of the specified country in the given size using the provided flag provider. The flag is |
| | | 20 | | /// </summary> |
| | | 21 | | /// <param name="provider">The flag provider to use for retrieving the flag.</param> |
| | | 22 | | /// <param name="size">The size of the flag to retrieve.</param> |
| | | 23 | | /// <returns>A MemoryStream containing the flag image data.</returns> |
| | | 24 | | /// <exception cref="InvalidOperationException">Thrown if the flag cannot be found.</exception> |
| | | 25 | | public MemoryStream GetFlag(ICountryFlagProvider provider, FlagSize size) |
| | | 26 | | { |
| | 0 | 27 | | var bytes = provider.GetBytes(country, size); |
| | 0 | 28 | | return bytes is not { Length: > 0 } ? throw new InvalidOperationException($"Flag not found for country '{cou |
| | | 29 | | } |
| | | 30 | | } |
| | | 31 | | } |
| | | 32 | | |