Skip to content

Commit d63f2b5

Browse files
committed
Merge branch 'maintenance/C#-9.0' into develop
Implements C# 9.0, and takes advantage of a number of syntactical shortcuts that it offers. This includes, notably, extensive use of pattern matching for constant comparisons (e.g., `is` and `is not` over `==`, `!=`, and `.Equals()`). It also includes support for implicitly typed constructors (i.e., `new()`) for scenarios where the type can be inferred by context. That's especially useful for property initializers, and particularly for generic collections where the type can be quite lengthy.
2 parents 9b87fc5 + b4b198b commit d63f2b5

86 files changed

Lines changed: 275 additions & 282 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

OnTopic.AspNetCore.Mvc.Host/OnTopic.AspNetCore.Mvc.Host.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<TargetFramework>netcoreapp3.0</TargetFramework>
55
<UserSecretsId>62eb85bf-f802-4afd-8bec-3d344e1cfc79</UserSecretsId>
66
<IsPackable>false</IsPackable>
7+
<LangVersion>9.0</LangVersion>
78
</PropertyGroup>
89

910
<ItemGroup>

OnTopic.AspNetCore.Mvc.Host/Views/Layout/_Layout.cshtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
<!-- /Page Header Area -->
2727

2828
<article itemscope itemtype="http://schema.org/WebPageElement" itemprop="mainContentOfPage" class="grid-container">
29-
<h1>@(Model.ContentType.Equals("PageGroup")? "Overview" : Model.Title)</h1>
29+
<h1>@(Model.ContentType is "PageGroup"? "Overview" : Model.Title)</h1>
3030
<p class="subtitle">@Model.Subtitle</p>
3131
<section class="body">
3232
<partial name="_TopicAttributes" />

OnTopic.AspNetCore.Mvc.Host/Views/Shared/Components/PageLevelNavigation/Default.cshtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<h2>PageLevelNavigation</h2>
44
<ul>
5-
@if (Model.NavigationRoot != null) {
5+
@if (Model.NavigationRoot is not null) {
66
foreach (var topic in Model.NavigationRoot.Children) {
77
<li><a href="@topic.WebPath">@(topic.ShortTitle?? topic.Title)</a></li>
88
}

OnTopic.AspNetCore.Mvc.Tests/OnTopic.AspNetCore.Mvc.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<PropertyGroup>
44
<TargetFramework>netcoreapp3.0</TargetFramework>
55
<IsPackable>false</IsPackable>
6+
<LangVersion>9.0</LangVersion>
67
</PropertyGroup>
78

89
<ItemGroup>

OnTopic.AspNetCore.Mvc.Tests/TopicControllerTest.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public TopicControllerTest() {
7373
RouteData = routes,
7474
ActionDescriptor = new ControllerActionDescriptor()
7575
};
76-
_context = new ControllerContext(actionContext);
76+
_context = new(actionContext);
7777

7878
}
7979

@@ -131,11 +131,11 @@ public void SitemapController_Index_ReturnsSitemapXml() {
131131

132132
var actionContext = new ActionContext {
133133
HttpContext = new DefaultHttpContext(),
134-
RouteData = new RouteData(),
134+
RouteData = new(),
135135
ActionDescriptor = new ControllerActionDescriptor()
136136
};
137137
var controller = new SitemapController(_topicRepository) {
138-
ControllerContext = new ControllerContext(actionContext)
138+
ControllerContext = new(actionContext)
139139
};
140140
var result = controller.Index() as ContentResult;
141141
var model = result.Content as string;

OnTopic.AspNetCore.Mvc.Tests/ValidateTopicAttributeTest.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public static ActionExecutingContext GetActionExecutingContext(Controller contro
4040

4141
var actionContext = new ActionContext(
4242
new DefaultHttpContext(),
43-
new RouteData(),
43+
new(),
4444
new ControllerActionDescriptor(),
4545
modelState
4646
);
@@ -63,10 +63,10 @@ public static ActionExecutingContext GetActionExecutingContext(Controller contro
6363
/// Generates a barebones <see cref="ControllerContext"/> for testing a controller.
6464
/// </summary>
6565
public static ControllerContext GetControllerContext() =>
66-
new ControllerContext(
67-
new ActionContext() {
66+
new(
67+
new() {
6868
HttpContext = new DefaultHttpContext(),
69-
RouteData = new RouteData(),
69+
RouteData = new(),
7070
ActionDescriptor = new ControllerActionDescriptor()
7171
}
7272
);
@@ -78,7 +78,7 @@ public static ControllerContext GetControllerContext() =>
7878
/// Generates a barebones <see cref="ControllerContext"/> for testing a controller.
7979
/// </summary>
8080
public static TopicController GetTopicController(Topic topic) =>
81-
new TopicController(
81+
new(
8282
new DummyTopicRepository(),
8383
new DummyTopicMappingService()
8484
) {

OnTopic.AspNetCore.Mvc/Components/MenuViewComponentBase{T}.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ IHierarchicalTopicMappingService<T> hierarchicalTopicMappingService
102102
await HierarchicalTopicMappingService.GetRootViewModelAsync(
103103
navigationRootTopic!,
104104
3,
105-
t => t.ContentType != "PageGroup"
105+
t => t.ContentType is not "PageGroup"
106106
).ConfigureAwait(false);
107107

108108
/*==========================================================================================================================

OnTopic.AspNetCore.Mvc/Components/NavigationTopicViewComponentBase{T}.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ IHierarchicalTopicMappingService<T> hierarchicalTopicMappingService
7777
/// <returns>The Topic associated with the current request.</returns>
7878
protected Topic? CurrentTopic {
7979
get {
80-
if (_currentTopic == null) {
80+
if (_currentTopic is null) {
8181
_currentTopic = TopicRepository.Load(RouteData);
8282
}
8383
return _currentTopic;

OnTopic.AspNetCore.Mvc/Components/PageLevelNavigationViewComponentBase{T}.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,9 @@ IHierarchicalTopicMappingService<T> hierarchicalTopicMappingService
7474
/*------------------------------------------------------------------------------------------------------------------------
7575
| Identify navigation root
7676
\-----------------------------------------------------------------------------------------------------------------------*/
77-
if (navigationRootTopic != null) {
77+
if (navigationRootTopic is not null) {
7878
while (
79-
navigationRootTopic.Parent != null &&
80-
!navigationRootTopic.ContentType.Equals("PageGroup", StringComparison.InvariantCulture)
79+
navigationRootTopic is not null and not ({ Parent: null } or { ContentType: "PageGroup" })
8180
) {
8281
navigationRootTopic = navigationRootTopic.Parent;
8382
}
@@ -86,7 +85,7 @@ IHierarchicalTopicMappingService<T> hierarchicalTopicMappingService
8685
/*------------------------------------------------------------------------------------------------------------------------
8786
| Return root
8887
\-----------------------------------------------------------------------------------------------------------------------*/
89-
return navigationRootTopic?.Parent == null? null : navigationRootTopic;
88+
return navigationRootTopic?.Parent is null? null : navigationRootTopic;
9089

9190
}
9291

OnTopic.AspNetCore.Mvc/Controllers/RedirectController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public virtual ActionResult Redirect(int topicId) {
5959
/*------------------------------------------------------------------------------------------------------------------------
6060
| Provide error handling
6161
\-----------------------------------------------------------------------------------------------------------------------*/
62-
if (topic == null) {
62+
if (topic is null) {
6363
return NotFound("Invalid TopicID.");
6464
}
6565

0 commit comments

Comments
 (0)