@@ -131,37 +131,91 @@ public void ClearTopics(string relationshipKey) {
131
131
/// </summary>
132
132
/// <param name="relationshipKey">The key of the relationship.</param>
133
133
/// <param name="topicKey">The key of the topic to be removed.</param>
134
+ /// <param name="isIncoming">
135
+ /// Notes that this is setting an internal relationship, and thus shouldn't set the reciprocal relationship.
136
+ /// </param>
134
137
/// <returns>
135
138
/// Returns true if the <see cref="Topic"/> is removed; returns false if either the relationship key or the
136
139
/// <see cref="Topic"/> cannot be found.
137
140
/// </returns>
138
- public bool RemoveTopic ( string relationshipKey , string topicKey ) {
141
+ public bool RemoveTopic ( string relationshipKey , string topicKey , bool isIncoming = false ) {
142
+
143
+ /*------------------------------------------------------------------------------------------------------------------------
144
+ | Validate contracts
145
+ \-----------------------------------------------------------------------------------------------------------------------*/
139
146
Contract . Requires < ArgumentNullException > ( ! String . IsNullOrWhiteSpace ( relationshipKey ) ) ;
140
147
Contract . Requires < ArgumentNullException > ( ! String . IsNullOrWhiteSpace ( topicKey ) ) ;
141
- if ( Contains ( relationshipKey ) ) {
142
- var topics = this [ relationshipKey ] ;
143
- return topics . Remove ( topicKey ) ;
148
+
149
+ /*------------------------------------------------------------------------------------------------------------------------
150
+ | Validate topic key
151
+ \-----------------------------------------------------------------------------------------------------------------------*/
152
+ var topics = Contains ( relationshipKey ) ? this [ relationshipKey ] : null ;
153
+ var topic = topics ? . Contains ( topicKey ) ?? false ? topics [ topicKey ] : null ;
154
+
155
+ if ( topics == null || topic == null ) {
156
+ return false ;
144
157
}
145
- return false ;
158
+
159
+ /*------------------------------------------------------------------------------------------------------------------------
160
+ | Call overload
161
+ \-----------------------------------------------------------------------------------------------------------------------*/
162
+ return RemoveTopic ( relationshipKey , topic , isIncoming ) ;
163
+
146
164
}
147
165
148
166
/// <summary>
149
167
/// Removes a specific <see cref="Topic"/> object associated with a specific relationship key.
150
168
/// </summary>
151
169
/// <param name="relationshipKey">The key of the relationship.</param>
152
170
/// <param name="topic">The topic to be removed.</param>
171
+ /// <param name="isIncoming">
172
+ /// Notes that this is setting an internal relationship, and thus shouldn't set the reciprocal relationship.
173
+ /// </param>
153
174
/// <returns>
154
175
/// Returns true if the <see cref="Topic"/> is removed; returns false if either the relationship key or the
155
176
/// <see cref="Topic"/> cannot be found.
156
177
/// </returns>
157
- public bool RemoveTopic ( string relationshipKey , Topic topic ) {
178
+ public bool RemoveTopic ( string relationshipKey , Topic topic , bool isIncoming = false ) {
179
+
180
+ /*------------------------------------------------------------------------------------------------------------------------
181
+ | Validate contracts
182
+ \-----------------------------------------------------------------------------------------------------------------------*/
158
183
Contract . Requires < ArgumentNullException > ( ! String . IsNullOrWhiteSpace ( relationshipKey ) ) ;
159
184
Contract . Requires ( topic ) ;
160
- if ( Contains ( relationshipKey ) ) {
161
- var topics = this [ relationshipKey ] ;
162
- return topics . Remove ( topic ) ;
185
+
186
+ /*------------------------------------------------------------------------------------------------------------------------
187
+ | Remove reciprocal relationship, if appropriate
188
+ \-----------------------------------------------------------------------------------------------------------------------*/
189
+ if ( ! isIncoming ) {
190
+ if ( _isIncoming ) {
191
+ throw new ArgumentException (
192
+ "You are attempting to remove an incoming relationship on a RelatedTopicCollection that is not flagged as " +
193
+ "IsIncoming" ,
194
+ nameof ( isIncoming )
195
+ ) ;
196
+ }
197
+ topic . IncomingRelationships . RemoveTopic ( relationshipKey , _parent , true ) ;
198
+ }
199
+
200
+ /*------------------------------------------------------------------------------------------------------------------------
201
+ | Validate relationshipKey
202
+ \-----------------------------------------------------------------------------------------------------------------------*/
203
+ var topics = Contains ( relationshipKey ) ? this [ relationshipKey ] : null ;
204
+
205
+ if ( topics == null || ! topics . Contains ( topic ) ) {
206
+ return false ;
163
207
}
164
- return false ;
208
+
209
+ /*------------------------------------------------------------------------------------------------------------------------
210
+ | Remove relationship
211
+ \-----------------------------------------------------------------------------------------------------------------------*/
212
+ topics . Remove ( topic ) ;
213
+
214
+ /*------------------------------------------------------------------------------------------------------------------------
215
+ | Remove true
216
+ \-----------------------------------------------------------------------------------------------------------------------*/
217
+ return true ;
218
+
165
219
}
166
220
167
221
/*==========================================================================================================================
0 commit comments