Skip to content

Commit 130a9d6

Browse files
committed
Refactor to use latest asp core features
1 parent 5159686 commit 130a9d6

10 files changed

Lines changed: 237 additions & 277 deletions

.editorconfig

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,85 @@ dotnet_analyzer_diagnostic.category-Globalization.severity = suggestion
55

66
# CA1031: Do not catch general exception types
77
dotnet_diagnostic.CA1031.severity = suggestion
8+
csharp_indent_labels = one_less_than_current
9+
csharp_using_directive_placement = outside_namespace:silent
10+
csharp_prefer_simple_using_statement = true:suggestion
11+
csharp_prefer_braces = true:silent
12+
csharp_style_namespace_declarations = file_scoped:silent
13+
csharp_style_prefer_method_group_conversion = true:silent
14+
csharp_style_prefer_top_level_statements = true:silent
15+
csharp_style_prefer_primary_constructors = true:suggestion
16+
csharp_style_expression_bodied_methods = false:silent
17+
csharp_style_expression_bodied_constructors = false:silent
18+
csharp_style_expression_bodied_operators = false:silent
19+
csharp_style_expression_bodied_properties = true:silent
20+
csharp_style_expression_bodied_indexers = true:silent
21+
csharp_style_expression_bodied_accessors = true:silent
22+
csharp_style_expression_bodied_lambdas = true:silent
23+
csharp_style_expression_bodied_local_functions = false:silent
24+
25+
[*.{cs,vb}]
26+
#### Naming styles ####
27+
28+
# Naming rules
29+
30+
dotnet_naming_rule.interface_should_be_begins_with_i.severity = suggestion
31+
dotnet_naming_rule.interface_should_be_begins_with_i.symbols = interface
32+
dotnet_naming_rule.interface_should_be_begins_with_i.style = begins_with_i
33+
34+
dotnet_naming_rule.types_should_be_pascal_case.severity = suggestion
35+
dotnet_naming_rule.types_should_be_pascal_case.symbols = types
36+
dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case
37+
38+
dotnet_naming_rule.non_field_members_should_be_pascal_case.severity = suggestion
39+
dotnet_naming_rule.non_field_members_should_be_pascal_case.symbols = non_field_members
40+
dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case
41+
42+
# Symbol specifications
43+
44+
dotnet_naming_symbols.interface.applicable_kinds = interface
45+
dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
46+
dotnet_naming_symbols.interface.required_modifiers =
47+
48+
dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum
49+
dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
50+
dotnet_naming_symbols.types.required_modifiers =
51+
52+
dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method
53+
dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
54+
dotnet_naming_symbols.non_field_members.required_modifiers =
55+
56+
# Naming styles
57+
58+
dotnet_naming_style.begins_with_i.required_prefix = I
59+
dotnet_naming_style.begins_with_i.required_suffix =
60+
dotnet_naming_style.begins_with_i.word_separator =
61+
dotnet_naming_style.begins_with_i.capitalization = pascal_case
62+
63+
dotnet_naming_style.pascal_case.required_prefix =
64+
dotnet_naming_style.pascal_case.required_suffix =
65+
dotnet_naming_style.pascal_case.word_separator =
66+
dotnet_naming_style.pascal_case.capitalization = pascal_case
67+
68+
dotnet_naming_style.pascal_case.required_prefix =
69+
dotnet_naming_style.pascal_case.required_suffix =
70+
dotnet_naming_style.pascal_case.word_separator =
71+
dotnet_naming_style.pascal_case.capitalization = pascal_case
72+
dotnet_style_operator_placement_when_wrapping = beginning_of_line
73+
tab_width = 4
74+
indent_size = 4
75+
end_of_line = crlf
76+
dotnet_style_coalesce_expression = true:suggestion
77+
dotnet_style_null_propagation = true:suggestion
78+
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion
79+
dotnet_style_prefer_auto_properties = true:silent
80+
dotnet_style_object_initializer = true:suggestion
81+
dotnet_style_collection_initializer = true:suggestion
82+
dotnet_style_prefer_simplified_boolean_expressions = true:suggestion
83+
dotnet_style_prefer_conditional_expression_over_assignment = true:silent
84+
dotnet_style_prefer_conditional_expression_over_return = true:silent
85+
dotnet_style_explicit_tuple_names = true:suggestion
86+
dotnet_style_prefer_inferred_tuple_names = true:suggestion
87+
dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion
88+
dotnet_style_prefer_compound_assignment = true:suggestion
89+
dotnet_style_namespace_match_folder = true:suggestion

Excursion360.Desktop/ConsoleHelper.cs

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,36 @@
1-
using System;
1+
namespace Excursion360.Desktop;
22

3-
namespace Excursion360.Desktop
3+
public static class ConsoleHelper
44
{
5-
public static class ConsoleHelper
5+
public static int SelectOneFromArray(string headerLine, string[] values)
66
{
7-
public static int SelectOneFromArray(string headerLine, string[] values)
7+
values = values ?? throw new ArgumentNullException(nameof(values));
8+
var index = 0;
9+
while (true)
810
{
9-
values = values ?? throw new ArgumentNullException(nameof(values));
10-
var index = 0;
11-
while (true)
11+
Console.Clear();
12+
Console.WriteLine(headerLine);
13+
for (int i = 0; i < values.Length; i++)
1214
{
13-
Console.Clear();
14-
Console.WriteLine(headerLine);
15-
for (int i = 0; i < values.Length; i++)
16-
{
17-
Console.BackgroundColor = index == i ? ConsoleColor.White : ConsoleColor.Black;
18-
Console.ForegroundColor = index == i ? ConsoleColor.Black : ConsoleColor.White;
19-
Console.WriteLine(values[i]);
20-
}
21-
Console.BackgroundColor = ConsoleColor.Black;
22-
Console.ForegroundColor = ConsoleColor.White;
23-
var key = Console.ReadKey();
24-
switch (key.Key)
25-
{
26-
case ConsoleKey.UpArrow:
27-
index = index <= 0 ? 0 : index - 1;
28-
break;
29-
case ConsoleKey.DownArrow:
30-
index = index + 1 >= values.Length ? values.Length - 1 : index + 1;
31-
break;
32-
case ConsoleKey.Enter:
33-
return index;
34-
default:
35-
break;
36-
}
15+
Console.BackgroundColor = index == i ? ConsoleColor.White : ConsoleColor.Black;
16+
Console.ForegroundColor = index == i ? ConsoleColor.Black : ConsoleColor.White;
17+
Console.WriteLine(values[i]);
18+
}
19+
Console.BackgroundColor = ConsoleColor.Black;
20+
Console.ForegroundColor = ConsoleColor.White;
21+
var key = Console.ReadKey();
22+
switch (key.Key)
23+
{
24+
case ConsoleKey.UpArrow:
25+
index = index <= 0 ? 0 : index - 1;
26+
break;
27+
case ConsoleKey.DownArrow:
28+
index = index + 1 >= values.Length ? values.Length - 1 : index + 1;
29+
break;
30+
case ConsoleKey.Enter:
31+
return index;
32+
default:
33+
break;
3734
}
3835
}
3936
}

Excursion360.Desktop/Excursion360.Desktop.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<OutputType>Exe</OutputType>
55
<TargetFramework>net8.0-windows</TargetFramework>
66
<IsTransformWebConfigDisabled>true</IsTransformWebConfigDisabled>
7+
<ImplicitUsings>enable</ImplicitUsings>
78
<Nullable>enable</Nullable>
89
</PropertyGroup>
910

Excursion360.Desktop/Extensions.cs

Lines changed: 13 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,20 @@
1-
using Microsoft.AspNetCore.Hosting;
2-
using Microsoft.Extensions.Logging;
3-
using Microsoft.Extensions.DependencyInjection;
4-
using System;
5-
using System.Collections.Generic;
6-
using System.Text;
7-
using Microsoft.Extensions.Hosting;
8-
using Microsoft.AspNetCore.Hosting.Server;
1+
using Microsoft.AspNetCore.Hosting.Server;
92
using Microsoft.AspNetCore.Hosting.Server.Features;
10-
using System.Linq;
113
using Microsoft.AspNetCore.Http.Features;
124

13-
namespace Excursion360.Desktop
5+
namespace Excursion360.Desktop;
6+
7+
static class Extensions
148
{
15-
static class Extensions
9+
public static ILogger CreateLogger(this IWebHost host, string categoryName)
10+
=> host.Services.GetRequiredService<ILoggerFactory>().CreateLogger(categoryName);
11+
public static Uri GetListeningUri(this IHost host)
1612
{
17-
public static ILogger CreateLogger(this IWebHost host, string categoryName)
18-
=> host.Services.GetRequiredService<ILoggerFactory>().CreateLogger(categoryName);
19-
public static Uri GetListeningUri(this IHost host)
20-
{
21-
return new Uri(host.Services
22-
.GetRequiredService<IServer>()
23-
.Features
24-
.GetRequiredFeature<IServerAddressesFeature>()
25-
.Addresses
26-
.Single(a => a.StartsWith("http:", StringComparison.Ordinal)));
27-
}
28-
public static IEnumerable<TSource> DistinctBy<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector)
29-
{
30-
HashSet<TKey> seenKeys = new HashSet<TKey>();
31-
foreach (TSource element in source)
32-
{
33-
if (seenKeys.Add(keySelector(element)))
34-
{
35-
yield return element;
36-
}
37-
}
38-
}
13+
return new Uri(host.Services
14+
.GetRequiredService<IServer>()
15+
.Features
16+
.GetRequiredFeature<IServerAddressesFeature>()
17+
.Addresses
18+
.Single(a => a.StartsWith("http:", StringComparison.Ordinal)));
3919
}
4020
}

0 commit comments

Comments
 (0)