@@ -33,14 +33,50 @@ public class Topic {
3333
3434 /*==========================================================================================================================
3535 | CONSTRUCTOR
36- >-----------=---------------------------------------------------------------------------------------------------------------
37- | ### NOTE JJC082715: The empty constructor is a prerequisite of the factory method, which relies on Activator to create a
38- | new instance of the object.
39- \-----------=-------------------------------------------------------------------------------------------------------------*/
36+ \-------------------------------------------------------------------------------------------------------------------------*/
4037 /// <summary>
41- /// Initializes a new instance of the <see cref="Topic"/> class.
38+ /// Initializes a new instance of a <see cref="Topic"/> class with a <see cref="Key"/>, <see cref="ContentType"/>, and,
39+ /// optionally, <see cref="Parent"/>, <see cref="Id"/>.
4240 /// </summary>
43- public Topic ( ) {
41+ /// <remarks>
42+ /// By default, when creating new attributes, the <see cref="AttributeValue"/>s for both <see cref="Key"/> and <see
43+ /// cref="ContentType"/> will be set to <see cref="AttributeValue.IsDirty"/>, which is required in order to correctly save
44+ /// new topics to the database. When the <paramref name="id"/> parameter is set, however, the <see
45+ /// cref="AttributeValue.IsDirty"/> property is set to <c>false</c>on <see cref="Key"/> and <see cref="ContentType"/>, as
46+ /// it is assumed these are being set to the same values currently used in the persistance store.
47+ /// </remarks>
48+ /// <param name="key">A string representing the key for the new topic instance.</param>
49+ /// <param name="contentType">A string representing the key of the target content type.</param>
50+ /// <param name="id">The unique identifier assigned by the data store for an existing topic.</param>
51+ /// <param name="parent">Optional topic to set as the new topic's parent.</param>
52+ /// <exception cref="ArgumentException">
53+ /// Thrown when the class representing the content type is found, but doesn't derive from <see cref="Topic"/>.
54+ /// </exception>
55+ /// <returns>A strongly-typed instance of the <see cref="Topic"/> class based on the target content type.</returns>
56+ public Topic ( string key , string contentType , Topic parent , int id = - 1 ) {
57+
58+ /*----------------------------------------------------------------------------------------------------------------------
59+ | Set core properties
60+ \---------------------------------------------------------------------------------------------------------------------*/
61+ Key = key ;
62+ ContentType = contentType ;
63+ Parent = parent ;
64+
65+ /*----------------------------------------------------------------------------------------------------------------------
66+ | If ID is set, ensure attributes are not marked as IsDirty
67+ \---------------------------------------------------------------------------------------------------------------------*/
68+ if ( id >= 0 ) {
69+ Id = id ;
70+ Attributes . SetValue ( "Key" , key , false , false ) ;
71+ Attributes . SetValue ( "ContentType" , contentType , false , false ) ;
72+ if ( parent != null ) {
73+ Attributes . SetValue ( "ParentId" , parent . Id . ToString ( ) , false , false ) ;
74+ }
75+ }
76+
77+ /*----------------------------------------------------------------------------------------------------------------------
78+ | Set relationships
79+ \---------------------------------------------------------------------------------------------------------------------*/
4480 Children = new TopicCollection ( this ) ;
4581 Attributes = new AttributeValueCollection ( this ) ;
4682 IncomingRelationships = new RelatedTopicCollection ( this , true ) ;
0 commit comments