Skip to content

Commit

Permalink
Merge branch 'feature/AttributeDictionary-constructors' into develop
Browse files Browse the repository at this point in the history
In OnTopic 5.2.0, the `TopicMappingService` may optionally call, if present, a constructor overload that accepts an `AttributeDictionary` argument as an alternative to relying on reflection to handle mapping. This puts the onus on the model developer to handle mapping of scalar attributes to (typically) properties. In turn, this provides better performance and more control (e.g., with the ability to map to private fields, if needed).
  • Loading branch information
JeremyCaney committed Jun 27, 2022
2 parents d8b36b7 + b0de3b0 commit e50b674
Show file tree
Hide file tree
Showing 17 changed files with 274 additions and 1 deletion.
12 changes: 11 additions & 1 deletion Areas/Courses/Models/LessonPagingTopicViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,17 @@ namespace GoldSim.Web.Courses.Models {
/// <summary>
/// Provides a strongly-typed data transfer object for handling next/back paging buttons on the Lesson pages.
/// </summary>
public record LessonPagingTopicViewModel: PageTopicViewModel {
public record LessonPagingTopicViewModel {

/*==========================================================================================================================
| PROPERTY: TITLE
\-------------------------------------------------------------------------------------------------------------------------*/
public string Title { get; init; }

/*==========================================================================================================================
| PROPERTY: WEB PATH
\-------------------------------------------------------------------------------------------------------------------------*/
public string WebPath { get; init; }

/*==========================================================================================================================
| LABEL
Expand Down
17 changes: 17 additions & 0 deletions Models/Associations/AssociatedContentItemViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,23 @@ namespace GoldSim.Web.Models.Associations {
/// </summary>
public record AssociatedContentItemViewModel: AssociatedTopicViewModel {

/*==========================================================================================================================
| CONSTRUCTOR
\-------------------------------------------------------------------------------------------------------------------------*/
/// <summary>
/// Initializes a new <see cref="AssociatedContentItemViewModel"/> with an <paramref name="attributes"/> dictionary.
/// </summary>
/// <param name="attributes">An <see cref="AttributeDictionary"/> of attribute values.</param>
public AssociatedContentItemViewModel(AttributeDictionary attributes) : base(attributes) {
Contract.Requires(attributes, nameof(attributes));
LearnMoreUrl = attributes.GetUri(nameof(LearnMoreUrl));
}

/// <summary>
/// Initializes a new <see cref="AssociatedContentItemViewModel"/> with no parameters.
/// </summary>
public AssociatedContentItemViewModel() { }

/*==========================================================================================================================
| KEY
\-------------------------------------------------------------------------------------------------------------------------*/
Expand Down
17 changes: 17 additions & 0 deletions Models/Associations/AssociatedTopicViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,23 @@ namespace GoldSim.Web.Models.Associations {
/// </summary>
public record AssociatedTopicViewModel: INavigableTopicViewModel {

/*==========================================================================================================================
| CONSTRUCTOR
\-------------------------------------------------------------------------------------------------------------------------*/
/// <summary>
/// Initializes a new <see cref="AssociatedTopicViewModel"/> with an <paramref name="attributes"/> dictionary.
/// </summary>
/// <param name="attributes">An <see cref="AttributeDictionary"/> of attribute values.</param>
public AssociatedTopicViewModel(AttributeDictionary attributes) {
Contract.Requires(attributes, nameof(attributes));
ShortTitle = attributes.GetValue(nameof(ShortTitle));
}

/// <summary>
/// Initializes a new <see cref="AssociatedTopicViewModel"/> with no parameters.
/// </summary>
public AssociatedTopicViewModel() { }

/*==========================================================================================================================
| WEB PATH
\-------------------------------------------------------------------------------------------------------------------------*/
Expand Down
17 changes: 17 additions & 0 deletions Models/Associations/CardViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,23 @@ namespace GoldSim.Web.Models.Associations {
/// </summary>
public record CardViewModel: AssociatedTopicViewModel, ICardViewModel {

/*==========================================================================================================================
| CONSTRUCTOR
\-------------------------------------------------------------------------------------------------------------------------*/
/// <summary>
/// Initializes a new <see cref="CardViewModel"/> with an <paramref name="attributes"/> dictionary.
/// </summary>
/// <param name="attributes">An <see cref="AttributeDictionary"/> of attribute values.</param>
public CardViewModel(AttributeDictionary attributes) : base(attributes) {
Contract.Requires(attributes, nameof(attributes));
ThumbnailImage = attributes.GetValue(nameof(ThumbnailImage));
}

/// <summary>
/// Initializes a new <see cref="CardViewModel"/> with no parameters.
/// </summary>
public CardViewModel() { }

/*==========================================================================================================================
| THUMBNAIL IMAGE
\-------------------------------------------------------------------------------------------------------------------------*/
Expand Down
18 changes: 18 additions & 0 deletions Models/ContentTypes/ApplicationBasePageTopicViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,24 @@ namespace GoldSim.Web.Models.ContentTypes {
/// </remarks>
public record ApplicationBasePageTopicViewModel : PageTopicViewModel, ICardViewModel {

/*==========================================================================================================================
| CONSTRUCTOR
\-------------------------------------------------------------------------------------------------------------------------*/
/// <summary>
/// Initializes a new <see cref="ApplicationBasePageTopicViewModel"/> with an <paramref name="attributes"/> dictionary.
/// </summary>
/// <param name="attributes">An <see cref="AttributeDictionary"/> of attribute values.</param>
public ApplicationBasePageTopicViewModel(AttributeDictionary attributes) : base(attributes) {
Contract.Requires(attributes, nameof(attributes));
ThumbnailImage = attributes.GetValue(nameof(ThumbnailImage));
Category = attributes.GetValue(nameof(Category));
}

/// <summary>
/// Initializes a new <see cref="ApplicationBasePageTopicViewModel"/> with no parameters.
/// </summary>
public ApplicationBasePageTopicViewModel() { }

/*==========================================================================================================================
| THUMBNAIL IMAGE
\-------------------------------------------------------------------------------------------------------------------------*/
Expand Down
17 changes: 17 additions & 0 deletions Models/ContentTypes/ApplicationIndexTopicViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,23 @@ public record ApplicationIndexTopicViewModel : PageTopicViewModel {
\-------------------------------------------------------------------------------------------------------------------------*/
bool _isFirst = true;

/*==========================================================================================================================
| CONSTRUCTOR
\-------------------------------------------------------------------------------------------------------------------------*/
/// <summary>
/// Initializes a new <see cref="ApplicationIndexTopicViewModel"/> with an <paramref name="attributes"/> dictionary.
/// </summary>
/// <param name="attributes">An <see cref="AttributeDictionary"/> of attribute values.</param>
public ApplicationIndexTopicViewModel(AttributeDictionary attributes) : base(attributes) {
Contract.Requires(attributes, nameof(attributes));
FilteredDocumentType = attributes.GetValue(nameof(FilteredDocumentType));
}

/// <summary>
/// Initializes a new <see cref="ApplicationIndexTopicViewModel"/> with no parameters.
/// </summary>
public ApplicationIndexTopicViewModel() { }

/*==========================================================================================================================
| FILTERED DOCUMENT TYPE
\-------------------------------------------------------------------------------------------------------------------------*/
Expand Down
21 changes: 21 additions & 0 deletions Models/ContentTypes/ApplicationPageTopicViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,27 @@ namespace GoldSim.Web.Models.ContentTypes {
/// </summary>
public record ApplicationPageTopicViewModel: ApplicationBasePageTopicViewModel {

/*==========================================================================================================================
| CONSTRUCTOR
\-------------------------------------------------------------------------------------------------------------------------*/
/// <summary>
/// Initializes a new <see cref="ApplicationPageTopicViewModel"/> with an <paramref name="attributes"/> dictionary.
/// </summary>
/// <param name="attributes">An <see cref="AttributeDictionary"/> of attribute values.</param>
public ApplicationPageTopicViewModel(AttributeDictionary attributes) : base(attributes) {
Contract.Requires(attributes, nameof(attributes));
Abstract = attributes.GetValue(nameof(Abstract));
ModelImage = attributes.GetValue(nameof(ModelImage));
CompareTo = attributes.GetValue(nameof(CompareTo));
LearnMoreUrl = attributes.GetUri(nameof(LearnMoreUrl));
LearnMoreLabel = attributes.GetValue(nameof(LearnMoreLabel))?? "Learn More";
}

/// <summary>
/// Initializes a new <see cref="ApplicationIndexTopicViewModel"/> with no parameters.
/// </summary>
public ApplicationPageTopicViewModel() { }

/*==========================================================================================================================
| ABSTRACT
\-------------------------------------------------------------------------------------------------------------------------*/
Expand Down
14 changes: 14 additions & 0 deletions Models/ContentTypes/ContentItems/FaqItemTopicViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,19 @@ namespace GoldSim.Web.Models.ContentTypes.ContentItems {
/// </summary>
public record FaqItemTopicViewModel: ContentItemTopicViewModel {

/*==========================================================================================================================
| CONSTRUCTOR
\-------------------------------------------------------------------------------------------------------------------------*/
/// <summary>
/// Initializes a new <see cref="FaqItemTopicViewModel"/> with an <paramref name="attributes"/> dictionary.
/// </summary>
/// <param name="attributes">An <see cref="AttributeDictionary"/> of attribute values.</param>
public FaqItemTopicViewModel(AttributeDictionary attributes) : base(attributes) { }

/// <summary>
/// Initializes a new <see cref="FaqItemTopicViewModel"/> with no parameters.
/// </summary>
public FaqItemTopicViewModel() { }

} // Class
} // Namespace
24 changes: 24 additions & 0 deletions Models/ContentTypes/ContentItems/TechnicalPaperTopicViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,30 @@ namespace GoldSim.Web.Models.ContentTypes.ContentItems {
/// </summary>
public record TechnicalPaperTopicViewModel {

/*==========================================================================================================================
| CONSTRUCTOR
\-------------------------------------------------------------------------------------------------------------------------*/
/// <summary>
/// Initializes a new <see cref="TechnicalPaperTopicViewModel"/> with an <paramref name="attributes"/> dictionary.
/// </summary>
/// <param name="attributes">An <see cref="AttributeDictionary"/> of attribute values.</param>
public TechnicalPaperTopicViewModel(AttributeDictionary attributes) {
Contract.Requires(attributes, nameof(attributes));
Category = attributes.GetValue(nameof(Category));
Authors = attributes.GetValue(nameof(Authors));
Publication = attributes.GetValue(nameof(Publication));
PublicationUrl = attributes.GetUri(nameof(PublicationUrl));
PublicationDate = attributes.GetDateTime(nameof(PublicationDate))?? PublicationDate;
LearnMoreUrl = attributes.GetUri(nameof(LearnMoreUrl));
DownloadLabel = attributes.GetValue(nameof(DownloadLabel));
Description = attributes.GetValue(nameof(Description));
}

/// <summary>
/// Initializes a new <see cref="TechnicalPaperTopicViewModel"/> with no parameters.
/// </summary>
public TechnicalPaperTopicViewModel() { }

/*==========================================================================================================================
| KEY
\-------------------------------------------------------------------------------------------------------------------------*/
Expand Down
14 changes: 14 additions & 0 deletions Models/ContentTypes/ExampleApplicationTopicViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,20 @@ namespace GoldSim.Web.Models.ContentTypes {
/// </summary>
public record ExampleApplicationTopicViewModel: ApplicationBasePageTopicViewModel {

/*==========================================================================================================================
| CONSTRUCTOR
\-------------------------------------------------------------------------------------------------------------------------*/
/// <summary>
/// Initializes a new <see cref="ExampleApplicationTopicViewModel"/> with an <paramref name="attributes"/> dictionary.
/// </summary>
/// <param name="attributes">An <see cref="AttributeDictionary"/> of attribute values.</param>
public ExampleApplicationTopicViewModel(AttributeDictionary attributes) : base(attributes) { }

/// <summary>
/// Initializes a new <see cref="ExampleApplicationTopicViewModel"/> with no parameters.
/// </summary>
public ExampleApplicationTopicViewModel() { }

/*==========================================================================================================================
| RELATIONSHIP: APPLICATIONS
\-------------------------------------------------------------------------------------------------------------------------*/
Expand Down
14 changes: 14 additions & 0 deletions Models/ContentTypes/ExampleIndexTopicViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,20 @@ namespace GoldSim.Web.Models.ContentTypes {
/// </summary>
public record ExampleIndexTopicViewModel: ApplicationIndexTopicViewModel {

/*==========================================================================================================================
| CONSTRUCTOR
\-------------------------------------------------------------------------------------------------------------------------*/
/// <summary>
/// Initializes a new <see cref="ExampleIndexTopicViewModel"/> with an <paramref name="attributes"/> dictionary.
/// </summary>
/// <param name="attributes">An <see cref="AttributeDictionary"/> of attribute values.</param>
public ExampleIndexTopicViewModel(AttributeDictionary attributes) : base(attributes) { }

/// <summary>
/// Initializes a new <see cref="ExampleIndexTopicViewModel"/> with no parameters.
/// </summary>
public ExampleIndexTopicViewModel() { }

/*==========================================================================================================================
| CATEGORY: ENVIRONMENTAL SYSTEMS
\-------------------------------------------------------------------------------------------------------------------------*/
Expand Down
14 changes: 14 additions & 0 deletions Models/ContentTypes/FaqTopicViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,19 @@ namespace GoldSim.Web.Models.ContentTypes {
/// </summary>
public record FaqTopicViewModel: ContentListTopicViewModel {

/*==========================================================================================================================
| CONSTRUCTOR
\-------------------------------------------------------------------------------------------------------------------------*/
/// <summary>
/// Initializes a new <see cref="FaqTopicViewModel"/> with an <paramref name="attributes"/> dictionary.
/// </summary>
/// <param name="attributes">An <see cref="AttributeDictionary"/> of attribute values.</param>
public FaqTopicViewModel(AttributeDictionary attributes) : base(attributes) { }

/// <summary>
/// Initializes a new <see cref="FaqTopicViewModel"/> with no parameters.
/// </summary>
public FaqTopicViewModel() { }

} // Class
} // Namespace
17 changes: 17 additions & 0 deletions Models/ContentTypes/HomeTopicViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,23 @@ namespace GoldSim.Web.Models.ContentTypes {
/// </summary>
public record HomeTopicViewModel: PageTopicViewModel {

/*==========================================================================================================================
| CONSTRUCTOR
\-------------------------------------------------------------------------------------------------------------------------*/
/// <summary>
/// Initializes a new <see cref="HomeTopicViewModel"/> with an <paramref name="attributes"/> dictionary.
/// </summary>
/// <param name="attributes">An <see cref="AttributeDictionary"/> of attribute values.</param>
public HomeTopicViewModel(AttributeDictionary attributes): base(attributes) {
Contract.Requires(attributes, nameof(attributes));
Introduction = attributes.GetValue(nameof(Introduction));
}

/// <summary>
/// Initializes a new <see cref="HomeTopicViewModel"/> with no parameters.
/// </summary>
public HomeTopicViewModel() { }

/*==========================================================================================================================
| INTRODUCTION
\-------------------------------------------------------------------------------------------------------------------------*/
Expand Down
17 changes: 17 additions & 0 deletions Models/ContentTypes/ModulePageTopicViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,23 @@ namespace GoldSim.Web.Models.ContentTypes {
/// </summary>
public record ModulePageTopicViewModel : PageTopicViewModel, ICardViewModel {

/*==========================================================================================================================
| CONSTRUCTOR
\-------------------------------------------------------------------------------------------------------------------------*/
/// <summary>
/// Initializes a new <see cref="ModulePageTopicViewModel"/> with an <paramref name="attributes"/> dictionary.
/// </summary>
/// <param name="attributes">An <see cref="AttributeDictionary"/> of attribute values.</param>
public ModulePageTopicViewModel(AttributeDictionary attributes) : base(attributes) {
Contract.Requires(attributes, nameof(attributes));
ThumbnailImage = attributes.GetValue(nameof(ThumbnailImage));
}

/// <summary>
/// Initializes a new <see cref="ModulePageTopicViewModel"/> with no parameters.
/// </summary>
public ModulePageTopicViewModel() { }

/*==========================================================================================================================
| THUMBNAIL
\-------------------------------------------------------------------------------------------------------------------------*/
Expand Down
14 changes: 14 additions & 0 deletions Models/ContentTypes/SearchTopicViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,19 @@ namespace GoldSim.Web.Models.ContentTypes {
/// </summary>
public record SearchTopicViewModel : PageTopicViewModel {

/*==========================================================================================================================
| CONSTRUCTOR
\-------------------------------------------------------------------------------------------------------------------------*/
/// <summary>
/// Initializes a new <see cref="SearchTopicViewModel"/> with an <paramref name="attributes"/> dictionary.
/// </summary>
/// <param name="attributes">An <see cref="AttributeDictionary"/> of attribute values.</param>
public SearchTopicViewModel(AttributeDictionary attributes) : base(attributes) { }

/// <summary>
/// Initializes a new <see cref="FaqTopicViewModel"/> with no parameters.
/// </summary>
public SearchTopicViewModel() { }

} // Class
} // Namespace
Loading

0 comments on commit e50b674

Please sign in to comment.