| | | 1 | | // ----------------------------------------------------------------------- |
| | | 2 | | // <copyright file="LabeledValue.cs" company="Stéphane ANDRE"> |
| | | 3 | | // Copyright (c) Stéphane ANDRE. All rights reserved. |
| | | 4 | | // </copyright> |
| | | 5 | | // ----------------------------------------------------------------------- |
| | | 6 | | |
| | | 7 | | #pragma warning disable IDE0130 // Namespace does not match folder structure |
| | | 8 | | namespace MyNet.Observable; |
| | | 9 | | #pragma warning restore IDE0130 // Namespace does not match folder structure |
| | | 10 | | |
| | | 11 | | /// <summary> |
| | | 12 | | /// Pairs a value with a culture-bound display label (without wrapper inheritance). |
| | | 13 | | /// </summary> |
| | | 14 | | /// <typeparam name="T">The value type.</typeparam> |
| | | 15 | | /// <param name="Value">The underlying value.</param> |
| | | 16 | | /// <param name="DisplayName">The localized label provider.</param> |
| | | 17 | | public sealed record LabeledValue<T>(T Value, IObservableValue<string> DisplayName) |
| | | 18 | | { |
| | | 19 | | /// <summary> |
| | | 20 | | /// Initializes a new instance of the <see cref="LabeledValue{T}"/> class with a resource key label. |
| | | 21 | | /// </summary> |
| | | 22 | | /// <param name="value">The underlying value.</param> |
| | | 23 | | /// <param name="resourceKey">The translation resource key.</param> |
| | | 24 | | public LabeledValue(T value, string resourceKey) |
| | 6 | 25 | | : this(value, new LocalizedString(resourceKey)) { } |
| | | 26 | | |
| | | 27 | | /// <inheritdoc /> |
| | 3 | 28 | | public override string ToString() => DisplayName.Value ?? string.Empty; |
| | | 29 | | } |
| | | 30 | | |