88using System . Collections . ObjectModel ;
99using System . Diagnostics . CodeAnalysis ;
1010using System . Linq ;
11+ using OnTopic . Collections . Specialized ;
1112using OnTopic . Internal . Diagnostics ;
1213using OnTopic . Internal . Reflection ;
1314using OnTopic . Repositories ;
@@ -25,7 +26,7 @@ namespace OnTopic.Attributes {
2526 /// The <see cref="Topic"/> class tracks these through its <see cref="Topic.Attributes"/> property, which is an instance of
2627 /// the <see cref="AttributeValueCollection"/> class.
2728 /// </remarks>
28- public class AttributeValueCollection : KeyedCollection < string , AttributeValue > {
29+ public class AttributeValueCollection : KeyedCollection < string , AttributeValue > , ITrackDirtyKeys {
2930
3031 /*==========================================================================================================================
3132 | DISPATCHER
@@ -73,6 +74,10 @@ internal AttributeValueCollection(Topic parentTopic) : base(StringComparer.Ordin
7374 /*==========================================================================================================================
7475 | METHOD: IS DIRTY
7576 \-------------------------------------------------------------------------------------------------------------------------*/
77+
78+ /// <inheritdoc/>
79+ public bool IsDirty ( ) => IsDirty ( false ) ;
80+
7681 /// <summary>
7782 /// Determine if <i>any</i> attributes in the <see cref="AttributeValueCollection"/> are dirty.
7883 /// </summary>
@@ -88,7 +93,7 @@ internal AttributeValueCollection(Topic parentTopic) : base(StringComparer.Ordin
8893 /// generated by e.g. the OnTopic Editor and, thus, may be irrelevant updates if no other attribute values have changed.
8994 /// </param>
9095 /// <returns>True if the attribute value is marked as dirty; otherwise false.</returns>
91- public bool IsDirty ( bool excludeLastModified = false )
96+ public bool IsDirty ( bool excludeLastModified )
9297 => DeletedAttributes . Count > 0 || Items . Any ( a =>
9398 a . IsDirty &&
9499 ( ! excludeLastModified || ! a . Key . StartsWith ( "LastModified" , StringComparison . OrdinalIgnoreCase ) )
@@ -103,18 +108,22 @@ public bool IsDirty(bool excludeLastModified = false)
103108 /// </c> is a state of the current <see cref="AttributeValue"/>, it does not support <c>inheritFromParent</c> or <c>
104109 /// inheritFromDerived</c> (which otherwise default to <c>true</c>).
105110 /// </remarks>
106- /// <param name="name ">The string identifier for the <see cref="AttributeValue"/>.</param>
111+ /// <param name="key ">The string identifier for the <see cref="AttributeValue"/>.</param>
107112 /// <returns>True if the attribute value is marked as dirty; otherwise false.</returns>
108- public bool IsDirty ( string name ) {
109- if ( ! Contains ( name ) ) {
113+ public bool IsDirty ( string key ) {
114+ if ( ! Contains ( key ) ) {
110115 return false ;
111116 }
112- return this [ name ] . IsDirty ;
117+ return this [ key ] . IsDirty ;
113118 }
114119
115120 /*==========================================================================================================================
116121 | METHOD: MARK CLEAN
117122 \-------------------------------------------------------------------------------------------------------------------------*/
123+
124+ /// <inheritdoc/>
125+ public void MarkClean ( ) => MarkClean ( ( DateTime ? ) null ) ;
126+
118127 /// <summary>
119128 /// Marks the collection—including all <see cref="AttributeValue"/> items—as clean, meaning they have been persisted to
120129 /// the underlying <see cref="ITopicRepository"/>.
@@ -128,7 +137,7 @@ public bool IsDirty(string name) {
128137 /// The <see cref="DateTime"/> value that the attributes were last saved. This corresponds to the <see cref="Topic.
129138 /// VersionHistory"/>.
130139 /// </param>
131- public void MarkClean ( DateTime ? version = null ) {
140+ public void MarkClean ( DateTime ? version ) {
132141 foreach ( var attribute in Items . Where ( a => a . IsDirty ) . ToArray ( ) ) {
133142 SetValue ( attribute . Key , attribute . Value , false , false , version ?? DateTime . UtcNow ) ;
134143 }
@@ -138,6 +147,10 @@ public void MarkClean(DateTime? version = null) {
138147 /*==========================================================================================================================
139148 | METHOD: MARK CLEAN
140149 \-------------------------------------------------------------------------------------------------------------------------*/
150+
151+ /// <inheritdoc/>
152+ public void MarkClean ( string key ) => MarkClean ( key , null ) ;
153+
141154 /// <summary>
142155 /// Marks an individual <see cref="AttributeValue"/> as clean.
143156 /// </summary>
@@ -146,14 +159,14 @@ public void MarkClean(DateTime? version = null) {
146159 /// mark an <see cref="AttributeValue"/> as clean. After this, <see cref="IsDirty(String)"/> will return <c>false</c> for
147160 /// that item until it is modified.
148161 /// </remarks>
149- /// <param name="name ">The string identifier for the <see cref="AttributeValue"/>.</param>
162+ /// <param name="key ">The string identifier for the <see cref="AttributeValue"/>.</param>
150163 /// <param name="version">
151164 /// The <see cref="DateTime"/> value that the attribute was last modified. This denotes the <see cref="Topic.
152165 /// VersionHistory"/> associated with the specific attribute.
153166 /// </param>
154- public void MarkClean ( string name , DateTime ? version = null ) {
155- if ( Contains ( name ) ) {
156- var attribute = this [ name ] ;
167+ public void MarkClean ( string key , DateTime ? version ) {
168+ if ( Contains ( key ) ) {
169+ var attribute = this [ key ] ;
157170 if ( attribute . IsDirty ) {
158171 SetValue ( attribute . Key , attribute . Value , false , false , version ?? DateTime . UtcNow ) ;
159172 }
0 commit comments