| | 1 | | using System; |
| | 2 | | using System.Collections.Generic; |
| | 3 | | using System.Globalization; |
| | 4 | | using NetTopologySuite.Features; |
| | 5 | |
|
| | 6 | | namespace Itinero.Geo; |
| | 7 | |
|
| | 8 | | /// <summary> |
| | 9 | | /// Extension methods related to attributes tables |
| | 10 | | /// </summary> |
| | 11 | | public static class AttributesTableExtensions |
| | 12 | | { |
| | 13 | | /// <summary> |
| | 14 | | /// Converts the given attributes table to attributes for Itinero. |
| | 15 | | /// </summary> |
| | 16 | | /// <param name="attributesTable">The attributes table.</param> |
| | 17 | | /// <returns>Attributes as string key-value pairs.</returns> |
| | 18 | | public static IEnumerable<(string key, string value)> ToAttributes(this IAttributesTable attributesTable) |
| 0 | 19 | | { |
| 0 | 20 | | var names = attributesTable.GetNames(); |
| 0 | 21 | | foreach (var name in names) |
| 0 | 22 | | { |
| 0 | 23 | | yield return (name, attributesTable[name].ToInvariantString()); |
| 0 | 24 | | } |
| 0 | 25 | | } |
| | 26 | |
|
| | 27 | | /// <summary> |
| | 28 | | /// Returns a string representing the object in a culture invariant way. |
| | 29 | | /// </summary> |
| | 30 | | private static string ToInvariantString(this object obj) |
| 0 | 31 | | { |
| 0 | 32 | | return obj switch |
| 0 | 33 | | { |
| 0 | 34 | | IConvertible convertible => convertible.ToString(CultureInfo.InvariantCulture), |
| 0 | 35 | | IFormattable formattable => formattable.ToString(null, CultureInfo.InvariantCulture), |
| 0 | 36 | | _ => obj.ToString() |
| 0 | 37 | | }; |
| 0 | 38 | | } |
| | 39 | | } |