-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAttributeViewModel.cs
More file actions
85 lines (72 loc) · 4.75 KB
/
AttributeViewModel.cs
File metadata and controls
85 lines (72 loc) · 4.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*==============================================================================================================================
| Author Ignia, LLC
| Client Ignia, LLC
| Project Topics Library
\=============================================================================================================================*/
namespace OnTopic.Editor.AspNetCore.Models {
/*============================================================================================================================
| CLASS: ATTRIBUTE VIEW MODEL
\---------------------------------------------------------------------------------------------------------------------------*/
/// <summary>
/// Provides access to both a <see cref="AttributeDescriptorViewModel"/> as well as the instance values for that attribute
/// from the currently selected <see cref="Topic"/>.
/// </summary>
public record AttributeViewModel {
/*==========================================================================================================================
| CONSTRUCTOR
\-------------------------------------------------------------------------------------------------------------------------*/
/// <summary>
/// Initializes a new instance of the <see cref="AttributeViewModel"/> class.
/// </summary>
public AttributeViewModel(
EditingTopicViewModel currentTopic,
AttributeDescriptorViewModel attributeDescriptor
) {
/*------------------------------------------------------------------------------------------------------------------------
| Validate parameters
\-----------------------------------------------------------------------------------------------------------------------*/
Contract.Requires(currentTopic, nameof(currentTopic));
Contract.Requires(attributeDescriptor, nameof(attributeDescriptor));
/*------------------------------------------------------------------------------------------------------------------------
| Set properties
\-----------------------------------------------------------------------------------------------------------------------*/
CurrentTopic = currentTopic;
AttributeDescriptor = attributeDescriptor;
/*------------------------------------------------------------------------------------------------------------------------
| Set values
\-----------------------------------------------------------------------------------------------------------------------*/
var key = AttributeDescriptor.Key!;
var topic = CurrentTopic;
Value = topic.Attributes.ContainsKey(key) ? topic.Attributes[key] : null;
InheritedValue = topic.InheritedAttributes.ContainsKey(key) ? topic.InheritedAttributes[key] : null;
}
/*==========================================================================================================================
| PROPERTY: ATTRIBUTE DESCRIPTOR
\-------------------------------------------------------------------------------------------------------------------------*/
/// <summary>
/// Provides the global definition for the attribute, as defined on the corresponding <see cref="ContentTypeDescriptor"/>.
/// </summary>
public AttributeDescriptorViewModel AttributeDescriptor { get; }
/*==========================================================================================================================
| PROPERTY: CURRENT TOPIC
\-------------------------------------------------------------------------------------------------------------------------*/
/// <summary>
/// Provides a reference to the <see cref="EditingTopicViewModel"/> that the user is currently editing.
/// </summary>
public EditingTopicViewModel CurrentTopic { get; }
/*==========================================================================================================================
| VALUE
\-------------------------------------------------------------------------------------------------------------------------*/
/// <summary>
/// Provides the current value, as defined on the corresponding <see cref="AttributeRecord"/> instance.
/// </summary>
public virtual string? Value { get; init; }
/*==========================================================================================================================
| INHERITED VALUE
\-------------------------------------------------------------------------------------------------------------------------*/
/// <summary>
/// Provides the inherited value, as defined on either parent or derived topics.
/// </summary>
public string? InheritedValue { get; init; }
} // Class
} // Namespace