Skip to content

Commit 565273f

Browse files
committed
Introduced new IKeyedTopicViewModel interface
One of the places where we rely on `ITopicViewModel` is for the `KeyedTopicViewModelCollection`. But that only necessitates a `Key`, so that each instance can be indexed by the collection. Obviously, the generic types will almost certainly have more properties, but as those are strongly typed once the generic has been constructed, that's not an issue. Given that, requiring the (overly) comprehensive `ITopicViewModel` is excessive. This provides a (very) lightweight, base interface for keyed (view) models.
1 parent f92ebde commit 565273f

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*==============================================================================================================================
2+
| Author Ignia, LLC
3+
| Client Ignia, LLC
4+
| Project Topics Library
5+
\=============================================================================================================================*/
6+
using System.Collections.ObjectModel;
7+
using System.ComponentModel.DataAnnotations;
8+
using System.Diagnostics.CodeAnalysis;
9+
using OnTopic.Mapping;
10+
11+
namespace OnTopic.Models {
12+
13+
/*============================================================================================================================
14+
| INTERFACE: KEYED TOPIC VIEW MODEL
15+
\---------------------------------------------------------------------------------------------------------------------------*/
16+
/// <summary>
17+
/// Ensures that a model maintains, at minimum, a <see cref="Key"/> property, necessary to support e.g. a <see cref="
18+
/// KeyedCollection{TKey, TValue}"/>.
19+
/// </summary>
20+
/// <remarks>
21+
/// It is not required that topic view models implement the <see cref="IKeyedTopicViewModel"/> interface for the <see cref="
22+
/// TopicMappingService"/> to correctly identify and map <see cref="Topic"/>s to topic view models. That said, the interface
23+
/// does ensure that those view models can be keyed, which is useful for, especially, child collections.
24+
/// </remarks>
25+
public interface IKeyedTopicViewModel {
26+
27+
/*==========================================================================================================================
28+
| PROPERTY: KEY
29+
\-------------------------------------------------------------------------------------------------------------------------*/
30+
/// <summary>
31+
/// Gets the topic's <see cref="Key"/> attribute, the primary text identifier for the <see cref="Topic"/>.
32+
/// </summary>
33+
/// <requires description="The value from the getter must not be null." exception="T:System.ArgumentNullException">
34+
/// value is not null
35+
/// </requires>
36+
[Required, NotNull, DisallowNull]
37+
string? Key { get; init; }
38+
39+
} //Class
40+
} //Namespace

0 commit comments

Comments
 (0)