33| Client Ignia, LLC
44| Project Topics Library
55\=============================================================================================================================*/
6+ using System ;
7+ using System . Diagnostics . Contracts ;
8+ using System . Linq ;
69using OnTopic . Collections ;
10+ using OnTopic . Querying ;
11+ using OnTopic . Repositories ;
712
813namespace OnTopic . Metadata {
914
@@ -13,6 +18,13 @@ namespace OnTopic.Metadata {
1318 /// <summary>
1419 /// Represents a collection of <see cref="ContentTypeDescriptor"/> objects.
1520 /// </summary>
21+ /// <remarks>
22+ /// While the <see cref="ContentTypeDescriptorCollection"/> can be used to store any collection of <see cref=
23+ /// "ContentTypeDescriptor"/> objects, it has additional tooling in the form of the <see cref="Refresh(
24+ /// ContentTypeDescriptor?)"/> as well as the <see cref="ContentTypeDescriptorCollection(ContentTypeDescriptor?)"/>
25+ /// constructor for handling a flattened list of <see cref="ContentTypeDescriptor"/>s used for the <see cref=
26+ /// "ITopicRepository.GetContentTypeDescriptors()"/> method.
27+ /// </remarks>
1628 public class ContentTypeDescriptorCollection : TopicCollection < ContentTypeDescriptor > {
1729
1830 /*==========================================================================================================================
@@ -24,5 +36,39 @@ public class ContentTypeDescriptorCollection : TopicCollection<ContentTypeDescri
2436 public ContentTypeDescriptorCollection ( ) : base ( null ) {
2537 }
2638
39+ /*==========================================================================================================================
40+ | REFRESH
41+ \-------------------------------------------------------------------------------------------------------------------------*/
42+ /// <summary>
43+ /// Updates the current instance of the <see cref="ContentTypeDescriptorCollection"/> based on a new root <see cref=
44+ /// "ContentTypeDescriptor"/>.
45+ /// </summary>
46+ /// <param name="rootContentType">The <see cref="ContentTypeDescriptor"/> from which to initialize the collection.</param>
47+ public void Refresh ( ContentTypeDescriptor ? rootContentType ) {
48+
49+ /*------------------------------------------------------------------------------------------------------------------------
50+ | Validate parameters
51+ \-----------------------------------------------------------------------------------------------------------------------*/
52+ if ( rootContentType == null || rootContentType . Children . Count == 0 ) {
53+ return ;
54+ }
55+
56+ /*------------------------------------------------------------------------------------------------------------------------
57+ | Clear any existing values
58+ \-----------------------------------------------------------------------------------------------------------------------*/
59+ Clear ( ) ;
60+
61+ /*------------------------------------------------------------------------------------------------------------------------
62+ | Add all ContentTypeDescriptors to collection
63+ \-----------------------------------------------------------------------------------------------------------------------*/
64+ var contentTypeDescriptors = rootContentType
65+ . FindAll ( t => typeof ( ContentTypeDescriptor ) . IsAssignableFrom ( t . GetType ( ) ) )
66+ . Cast < ContentTypeDescriptor > ( ) ;
67+ foreach ( var contentType in contentTypeDescriptors ) {
68+ Add ( ( ContentTypeDescriptor ) contentType ) ;
69+ }
70+
71+ }
72+
2773 } //Class
2874} //Namespace
0 commit comments