| | 1 | | namespace Songhay.Extensions; |
| | 2 | |
|
| | 3 | | /// <summary> |
| | 4 | | /// Extensions of <see cref="DisplayItemModel"/>. |
| | 5 | | /// </summary> |
| | 6 | | public static class DisplayItemModelExtensions |
| | 7 | | { |
| | 8 | | /// <summary> |
| | 9 | | /// Returns <c>true</c> when the item has the <see cref="DisplayItemModel.Tag"/> |
| | 10 | | /// based on the specified evaluator. |
| | 11 | | /// </summary> |
| | 12 | | /// <param name="data">The <see cref="DisplayItemModel"/>.</param> |
| | 13 | | /// <param name="evaluator">The predicate for evaluating <see cref="DisplayItemModel.Tag"/>.</param> |
| | 14 | | public static bool HasTag(this DisplayItemModel? data, Func<object?, bool>? evaluator) => |
| 0 | 15 | | data != null && evaluator != null && evaluator.Invoke(data.Tag); |
| | 16 | |
|
| | 17 | | /// <summary> |
| | 18 | | /// Converts the <see cref="DisplayItemModel"/> into a menu display item model. |
| | 19 | | /// </summary> |
| | 20 | | /// <param name="data">The <see cref="DisplayItemModel"/>.</param> |
| | 21 | | public static MenuDisplayItemModel? ToMenuDisplayItemModel(this DisplayItemModel? data) => |
| 0 | 22 | | data as MenuDisplayItemModel; |
| | 23 | |
|
| | 24 | | /// <summary> |
| | 25 | | /// Fluently sets <see cref="DisplayItemModel.Tag"/>. |
| | 26 | | /// </summary> |
| | 27 | | /// <param name="data">The <see cref="DisplayItemModel"/>.</param> |
| | 28 | | /// <param name="tag">The value of <see cref="DisplayItemModel.Tag"/>.</param> |
| | 29 | | public static DisplayItemModel? WithTag(this DisplayItemModel? data, object tag) |
| 0 | 30 | | { |
| 0 | 31 | | if (data == null) return null; |
| | 32 | |
|
| 0 | 33 | | data.Tag = tag; |
| | 34 | |
|
| 0 | 35 | | return data; |
| 0 | 36 | | } |
| | 37 | | } |