Skip to content

Commit 718aea5

Browse files
committed
Merge branch 'maintenance/code-cleanup' into develop
Added missing XML documentation for a couple of classes. Implemented more succinct pattern matching for the `SampleActivator`.
2 parents d8d41b7 + 306e5c7 commit 718aea5

File tree

3 files changed

+123
-24
lines changed

3 files changed

+123
-24
lines changed

OnTopic.AspNetCore.Mvc.Host/SampleActivator.cs

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,13 @@ public object Create(ControllerContext context) {
9797
/*------------------------------------------------------------------------------------------------------------------------
9898
| Configure and return appropriate controller
9999
\-----------------------------------------------------------------------------------------------------------------------*/
100-
if (type == typeof(TopicController)) {
101-
return new TopicController(_topicRepository, _topicMappingService);
102-
}
103-
if (type == typeof(SitemapController)) {
104-
return new SitemapController(_topicRepository);
105-
}
106-
else {
107-
throw new Exception($"Unknown controller {type.Name}");
108-
}
100+
return type.Name switch {
101+
nameof(TopicController) =>
102+
new TopicController(_topicRepository, _topicMappingService),
103+
nameof(SitemapController) =>
104+
new SitemapController(_topicRepository),
105+
_ => throw new Exception($"Unknown controller {type.Name}")
106+
};
109107

110108
}
111109

@@ -123,15 +121,13 @@ public object Create(ViewComponentContext context) {
123121
/*------------------------------------------------------------------------------------------------------------------------
124122
| Configure and return appropriate view component
125123
\-----------------------------------------------------------------------------------------------------------------------*/
126-
if (type == typeof(MenuViewComponent)) {
127-
return new MenuViewComponent(_topicRepository, _hierarchicalMappingService);
128-
}
129-
else if (type == typeof(PageLevelNavigationViewComponent)) {
130-
return new PageLevelNavigationViewComponent(_topicRepository, _hierarchicalMappingService);
131-
}
132-
else {
133-
throw new Exception($"Unknown view component {type.Name}");
134-
}
124+
return type.Name switch {
125+
nameof(MenuViewComponent) =>
126+
new MenuViewComponent(_topicRepository, _hierarchicalMappingService),
127+
nameof(PageLevelNavigationViewComponent) =>
128+
new PageLevelNavigationViewComponent(_topicRepository, _hierarchicalMappingService),
129+
_ => throw new Exception($"Unknown view component {type.Name}")
130+
};
135131

136132
}
137133

OnTopic.AspNetCore.Mvc/Models/NavigationViewModel{T}.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,40 @@ namespace OnTopic.AspNetCore.Mvc.Models {
2727
/// </remarks>
2828
public class NavigationViewModel<T> where T : class, INavigationTopicViewModel<T> {
2929

30+
/*==========================================================================================================================
31+
| NAVIGATION ROOT
32+
\-------------------------------------------------------------------------------------------------------------------------*/
33+
/// <summary>
34+
/// Represents the root element in the navigation.
35+
/// </summary>
36+
/// <remarks>
37+
/// Since this implements <see cref="IHierarchicalTopicViewModel{T}"/>, it may include multiple levels of children. By
38+
/// implementing it as a generic, each site or application can provide its own <see cref="INavigationTopicViewModel{T}"/>
39+
/// implementation, thus potentially extending the schema with properties relevant to that site's navigation. For example,
40+
/// a site may optionally add an <c>IconUrl</c> property if it wishes to assign unique icons to each link in the
41+
/// navigation.
42+
/// </remarks>
3043
public T? NavigationRoot { get; set; }
44+
45+
/*==========================================================================================================================
46+
| CURRENT KEY
47+
\-------------------------------------------------------------------------------------------------------------------------*/
48+
/// <summary>
49+
/// The <see cref="Topic.GetUniqueKey()"/> representing the path to the current <see cref="Topic"/>.
50+
/// </summary>
51+
/// <remarks>
52+
/// <para>
53+
/// In order to determine whether any given <see cref="INavigationTopicViewModel{T}.IsSelected(string)"/>, the views
54+
/// will need to know where in the hierarchy the user currently is. By storing this on the <see
55+
/// cref="NavigationViewModel{T}"/> used as the root view model for every navigation component, we ensure that the views
56+
/// always have access to this information.
57+
/// </para>
58+
/// <para>
59+
/// It's worth noting that while this <i>could</i> be stored on the <see cref="INavigationTopicViewModel{T}"/> itself,
60+
/// that would prevent those values from being cached. As such, it's preferrable to keep the navigation nodes stateless,
61+
/// and maintaining state exclusively in the <see cref="NavigationViewModel{T}"/> itself.
62+
/// </para>
63+
/// </remarks>
3164
public string CurrentKey { get; set; } = default!;
3265

3366
} //Class

OnTopic/Mapping/Annotations/Relationships.cs

Lines changed: 76 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,103 @@
44
| Project Topics Library
55
\=============================================================================================================================*/
66
using System;
7+
using OnTopic.Metadata;
78

89
namespace OnTopic.Mapping.Annotations {
910

1011
/*============================================================================================================================
1112
| ENUM: RELATIONSHIPS
1213
\---------------------------------------------------------------------------------------------------------------------------*/
1314
/// <summary>
14-
/// Enum that allows one or more relationship types to be specified.
15+
/// Allows one or more relationship types to be specified.
1516
/// </summary>
1617
/// <remarks>
17-
/// This differs from <see cref="RelationshipType"/>, which only allows <i>one</i> relationship to be specified.
18+
/// <para>
19+
/// The <see cref="TopicMappingService"/> and <see cref="FollowAttribute"/> use the <see cref="Relationships"/> enum to
20+
/// determine what relationships should be mapped—or followed as part of the mapping process. This helps constrain the
21+
/// scope of the object graph to only include the data needed for a given view, or vice verse. That said, the <see
22+
/// cref="Relationships"/> enum can be used any place where the code needs to model multiple types of relationships
23+
/// relevant to the <see cref="Topic"/> class and its view models.
24+
/// </para>
25+
/// <para>
26+
/// This differs from <see cref="RelationshipType"/>, which only allows <i>one</i> relationship to be specified.
27+
/// </para>
1828
/// </remarks>
1929
[Flags]
2030
public enum Relationships {
2131

22-
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
23-
32+
/*==========================================================================================================================
33+
| NONE
34+
\-------------------------------------------------------------------------------------------------------------------------*/
35+
/// <summary>
36+
/// Do not follow any relationships.
37+
/// </summary>
2438
None = 0,
39+
40+
/*==========================================================================================================================
41+
| PARENTS
42+
\-------------------------------------------------------------------------------------------------------------------------*/
43+
/// <summary>
44+
/// Map <see cref="Topic.Parent"/> references.
45+
/// </summary>
2546
Parents = 1,
47+
48+
/*==========================================================================================================================
49+
| CHILDREN
50+
\-------------------------------------------------------------------------------------------------------------------------*/
51+
/// <summary>
52+
/// Map <see cref="Topic.Children"/> references, or properties marked as <see cref="RelationshipType.Children"/>.
53+
/// </summary>
2654
Children = 1 << 1,
55+
56+
/*==========================================================================================================================
57+
| RELATIONSHIPS
58+
\-------------------------------------------------------------------------------------------------------------------------*/
59+
/// <summary>
60+
/// Map <see cref="Topic.Relationships"/> references, or properties marked as <see cref="RelationshipType.Relationship"/>.
61+
/// </summary>
2762
Relationships = 1 << 2,
63+
64+
/*==========================================================================================================================
65+
| INCOMING RELATIONSHIPS
66+
\-------------------------------------------------------------------------------------------------------------------------*/
67+
/// <summary>
68+
/// Map <see cref="Topic.IncomingRelationships"/> references, or properties marked as <see
69+
/// cref="RelationshipType.IncomingRelationship"/>.
70+
/// </summary>
2871
IncomingRelationships = 1 << 3,
72+
73+
/*==========================================================================================================================
74+
| MAPPED COLLECTIONS
75+
\-------------------------------------------------------------------------------------------------------------------------*/
76+
/// <summary>
77+
/// Map to any collection on the <see cref="Topic"/> with either the same property name, or which corresponds to the <see
78+
/// cref="AttributeKeyAttribute.Value"/>.
79+
/// </summary>
80+
/// <remarks>
81+
/// This allows mapping of custom collection, such as <see cref="ContentTypeDescriptor.AttributeDescriptors"/>.
82+
/// </remarks>
2983
MappedCollections = 1 << 4,
84+
85+
/*==========================================================================================================================
86+
| REFERENCES
87+
\-------------------------------------------------------------------------------------------------------------------------*/
88+
/// <summary>
89+
/// Map topic pointer references, such as <see cref="Topic.DerivedTopic"/>.
90+
/// </summary>
91+
/// <remarks>
92+
/// By convention, <see cref="References"/> types refer to a <see cref="AttributeDescriptor"/>, <see
93+
/// cref="AttributeKeyAttribute.Value"/>, or property identifier ending in <c>Id</c>.
94+
/// </remarks>
3095
References = 1 << 5,
31-
All = Parents | Children | Relationships | IncomingRelationships | MappedCollections | References
3296

33-
#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member
97+
/*==========================================================================================================================
98+
| ALL
99+
\-------------------------------------------------------------------------------------------------------------------------*/
100+
/// <summary>
101+
/// Map all relationship types.
102+
/// </summary>
103+
All = Parents | Children | Relationships | IncomingRelationships | MappedCollections | References
34104

35105
} //Enum
36106
} //Namespace

0 commit comments

Comments
 (0)