| | 1 | | using Itinero.Routes; |
| | 2 | |
|
| | 3 | | namespace Itinero.Instructions.Types; |
| | 4 | |
|
| | 5 | | /// <summary> |
| | 6 | | /// Extensions on top of the route object to help with instruction generation. |
| | 7 | | /// </summary> |
| | 8 | | public static class RouteExtensions |
| | 9 | | { |
| | 10 | | /// <summary> |
| | 11 | | /// Gets the attribute or return a default value. |
| | 12 | | /// </summary> |
| | 13 | | /// <param name="meta">The meta route object.</param> |
| | 14 | | /// <param name="key">The key of the attribute to get.</param> |
| | 15 | | /// <returns>The value if any, null otherwise.</returns> |
| | 16 | | public static string? GetAttributeOrNull(this Route.Meta? meta, string key) |
| 17 | 17 | | { |
| 17 | 18 | | if (meta == null) |
| 0 | 19 | | { |
| 0 | 20 | | return default; |
| | 21 | | } |
| | 22 | |
|
| 178 | 23 | | foreach (var (k, value) in meta.Attributes) |
| 68 | 24 | | { |
| 68 | 25 | | if (k.Equals(key)) |
| 9 | 26 | | { |
| 9 | 27 | | return value; |
| | 28 | | } |
| 59 | 29 | | } |
| | 30 | |
|
| 8 | 31 | | return default; |
| 17 | 32 | | } |
| | 33 | | } |