Skip to content

Commit 4c8a30e

Browse files
committed
Refactor to file-scoped namespaces
1 parent 4ff0317 commit 4c8a30e

37 files changed

+813
-850
lines changed

samples/MvvmSample.Core/Helpers/MarkdownHelper.cs

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,25 @@
66
using System.Linq;
77
using System.Text.RegularExpressions;
88

9-
namespace MvvmSample.Core.Helpers
9+
namespace MvvmSample.Core.Helpers;
10+
11+
/// <summary>
12+
/// A simple class to help with basic operations on markdown documents.
13+
/// </summary>
14+
public static class MarkdownHelper
1015
{
1116
/// <summary>
12-
/// A simple class to help with basic operations on markdown documents.
17+
/// Gets all the paragraphs in a given markdown document.
1318
/// </summary>
14-
public static class MarkdownHelper
19+
/// <param name="text">The input markdown document.</param>
20+
/// <returns>The raw paragraphs from <paramref name="text"/>.</returns>
21+
public static IReadOnlyDictionary<string, string> GetParagraphs(string text)
1522
{
16-
/// <summary>
17-
/// Gets all the paragraphs in a given markdown document.
18-
/// </summary>
19-
/// <param name="text">The input markdown document.</param>
20-
/// <returns>The raw paragraphs from <paramref name="text"/>.</returns>
21-
public static IReadOnlyDictionary<string, string> GetParagraphs(string text)
22-
{
23-
return
24-
Regex.Matches(text, @"(?<=\W)#+ ([^\n]+).+?(?=\W#|$)", RegexOptions.Singleline)
25-
.OfType<Match>()
26-
.ToDictionary(
27-
m => m.Groups[1].Value.Trim().Replace("&lt;", "<"),
28-
m => m.Groups[0].Value.Trim().Replace("&lt;", "<").Replace("[!WARNING]", "**WARNING:**").Replace("[!NOTE]", "**NOTE:**"));
29-
}
23+
return
24+
Regex.Matches(text, @"(?<=\W)#+ ([^\n]+).+?(?=\W#|$)", RegexOptions.Singleline)
25+
.OfType<Match>()
26+
.ToDictionary(
27+
m => m.Groups[1].Value.Trim().Replace("&lt;", "<"),
28+
m => m.Groups[0].Value.Trim().Replace("&lt;", "<").Replace("[!WARNING]", "**WARNING:**").Replace("[!NOTE]", "**NOTE:**"));
3029
}
3130
}

samples/MvvmSample.Core/Models/Post.cs

Lines changed: 50 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -6,73 +6,72 @@
66
using System.Linq;
77
using System.Text.Json.Serialization;
88

9-
namespace MvvmSample.Core.Models
9+
namespace MvvmSample.Core.Models;
10+
11+
/// <summary>
12+
/// A class for a query for posts in a given subreddit.
13+
/// </summary>
14+
public sealed class PostsQueryResponse
1015
{
1116
/// <summary>
12-
/// A class for a query for posts in a given subreddit.
17+
/// Gets or sets the listing data for the response.
1318
/// </summary>
14-
public sealed class PostsQueryResponse
15-
{
16-
/// <summary>
17-
/// Gets or sets the listing data for the response.
18-
/// </summary>
19-
[JsonPropertyName("data")]
20-
public PostListing? Data { get; set; }
21-
}
19+
[JsonPropertyName("data")]
20+
public PostListing? Data { get; set; }
21+
}
2222

23+
/// <summary>
24+
/// A class for a Reddit listing of posts.
25+
/// </summary>
26+
public sealed class PostListing
27+
{
2328
/// <summary>
24-
/// A class for a Reddit listing of posts.
29+
/// Gets or sets the items in this listing.
2530
/// </summary>
26-
public sealed class PostListing
27-
{
28-
/// <summary>
29-
/// Gets or sets the items in this listing.
30-
/// </summary>
31-
[JsonPropertyName("children")]
32-
public IList<PostData>? Items { get; set; }
33-
}
31+
[JsonPropertyName("children")]
32+
public IList<PostData>? Items { get; set; }
33+
}
3434

35+
/// <summary>
36+
/// A wrapping class for a post.
37+
/// </summary>
38+
public sealed class PostData
39+
{
3540
/// <summary>
36-
/// A wrapping class for a post.
41+
/// Gets or sets the <see cref="Post"/> instance.
3742
/// </summary>
38-
public sealed class PostData
39-
{
40-
/// <summary>
41-
/// Gets or sets the <see cref="Post"/> instance.
42-
/// </summary>
43-
[JsonPropertyName("data")]
44-
public Post? Data { get; set; }
45-
}
43+
[JsonPropertyName("data")]
44+
public Post? Data { get; set; }
45+
}
4646

47+
/// <summary>
48+
/// A simple model for a Reddit post.
49+
/// </summary>
50+
public sealed class Post
51+
{
4752
/// <summary>
48-
/// A simple model for a Reddit post.
53+
/// Gets or sets the title of the post.
4954
/// </summary>
50-
public sealed class Post
51-
{
52-
/// <summary>
53-
/// Gets or sets the title of the post.
54-
/// </summary>
55-
[JsonPropertyName("title")]
56-
public string? Title { get; set; }
55+
[JsonPropertyName("title")]
56+
public string? Title { get; set; }
5757

58-
/// <summary>
59-
/// Gets or sets the URL to the post thumbnail, if present.
60-
/// </summary>
61-
[JsonPropertyName("thumbnail")]
62-
public string? Thumbnail { get; set; }
58+
/// <summary>
59+
/// Gets or sets the URL to the post thumbnail, if present.
60+
/// </summary>
61+
[JsonPropertyName("thumbnail")]
62+
public string? Thumbnail { get; set; }
6363

64-
/// <summary>
65-
/// Gets the text of the post.
66-
/// </summary>
67-
/// <remarks>
68-
/// Here we're just hardcoding some sample text to simplify how posts are displayed.
69-
/// Normally, not all posts have a self text post available.
70-
/// </remarks>
71-
[JsonIgnore]
72-
public string SelfText { get; } = string.Join(" ", Enumerable.Repeat(
64+
/// <summary>
65+
/// Gets the text of the post.
66+
/// </summary>
67+
/// <remarks>
68+
/// Here we're just hardcoding some sample text to simplify how posts are displayed.
69+
/// Normally, not all posts have a self text post available.
70+
/// </remarks>
71+
[JsonIgnore]
72+
public string SelfText { get; } = string.Join(" ", Enumerable.Repeat(
7373
@"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
7474
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
7575
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
7676
Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.", 20));
77-
}
7877
}

samples/MvvmSample.Core/Services/IFileService.cs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,22 @@
55
using System.IO;
66
using System.Threading.Tasks;
77

8-
namespace MvvmSample.Core.Services
8+
namespace MvvmSample.Core.Services;
9+
10+
/// <summary>
11+
/// The default <see langword="interface"/> for a service that handles files.
12+
/// </summary>
13+
public interface IFilesService
914
{
1015
/// <summary>
11-
/// The default <see langword="interface"/> for a service that handles files.
16+
/// Gets the path of the installation directory.
1217
/// </summary>
13-
public interface IFilesService
14-
{
15-
/// <summary>
16-
/// Gets the path of the installation directory.
17-
/// </summary>
18-
string InstallationPath { get; }
18+
string InstallationPath { get; }
1919

20-
/// <summary>
21-
/// Gets a readonly <see cref="Stream"/> for a file at a specified path.
22-
/// </summary>
23-
/// <param name="path">The path of the file to retrieve.</param>
24-
/// <returns>The <see cref="Stream"/> for the specified file.</returns>
25-
Task<Stream> OpenForReadAsync(string path);
26-
}
20+
/// <summary>
21+
/// Gets a readonly <see cref="Stream"/> for a file at a specified path.
22+
/// </summary>
23+
/// <param name="path">The path of the file to retrieve.</param>
24+
/// <returns>The <see cref="Stream"/> for the specified file.</returns>
25+
Task<Stream> OpenForReadAsync(string path);
2726
}

samples/MvvmSample.Core/Services/IRedditService.cs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,17 @@
66
using MvvmSample.Core.Models;
77
using Refit;
88

9-
namespace MvvmSample.Core.Services
9+
namespace MvvmSample.Core.Services;
10+
11+
/// <summary>
12+
/// An interface for a simple Reddit service.
13+
/// </summary>
14+
public interface IRedditService
1015
{
1116
/// <summary>
12-
/// An interface for a simple Reddit service.
17+
/// Get a list of posts from a given subreddit
1318
/// </summary>
14-
public interface IRedditService
15-
{
16-
/// <summary>
17-
/// Get a list of posts from a given subreddit
18-
/// </summary>
19-
/// <param name="subreddit">The subreddit name.</param>
20-
[Get("/r/{subreddit}/.json")]
21-
Task<PostsQueryResponse> GetSubredditPostsAsync(string subreddit);
22-
}
19+
/// <param name="subreddit">The subreddit name.</param>
20+
[Get("/r/{subreddit}/.json")]
21+
Task<PostsQueryResponse> GetSubredditPostsAsync(string subreddit);
2322
}

samples/MvvmSample.Core/Services/ISettingsService.cs

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,25 @@
44

55
using System;
66

7-
namespace MvvmSample.Core.Services
7+
namespace MvvmSample.Core.Services;
8+
9+
/// <summary>
10+
/// The default <see langword="interface"/> for the settings manager used in the app.
11+
/// </summary>
12+
public interface ISettingsService
813
{
914
/// <summary>
10-
/// The default <see langword="interface"/> for the settings manager used in the app.
15+
/// Assigns a value to a settings key.
1116
/// </summary>
12-
public interface ISettingsService
13-
{
14-
/// <summary>
15-
/// Assigns a value to a settings key.
16-
/// </summary>
17-
/// <typeparam name="T">The type of the object bound to the key.</typeparam>
18-
/// <param name="key">The key to check.</param>
19-
/// <param name="value">The value to assign to the setting key.</param>
20-
void SetValue<T>(string key, T? value);
17+
/// <typeparam name="T">The type of the object bound to the key.</typeparam>
18+
/// <param name="key">The key to check.</param>
19+
/// <param name="value">The value to assign to the setting key.</param>
20+
void SetValue<T>(string key, T? value);
2121

22-
/// <summary>
23-
/// Reads a value from the current <see cref="IServiceProvider"/> instance and returns its casting in the right type.
24-
/// </summary>
25-
/// <typeparam name="T">The type of the object to retrieve.</typeparam>
26-
/// <param name="key">The key associated to the requested object.</param>
27-
T? GetValue<T>(string key);
28-
}
22+
/// <summary>
23+
/// Reads a value from the current <see cref="IServiceProvider"/> instance and returns its casting in the right type.
24+
/// </summary>
25+
/// <typeparam name="T">The type of the object to retrieve.</typeparam>
26+
/// <param name="key">The key associated to the requested object.</param>
27+
T? GetValue<T>(string key);
2928
}

samples/MvvmSample.Core/ViewModels/AsyncRelayCommandPageViewModel.cs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,21 @@
55
using System.Threading.Tasks;
66
using CommunityToolkit.Mvvm.Input;
77

8-
namespace MvvmSample.Core.ViewModels
8+
namespace MvvmSample.Core.ViewModels;
9+
10+
public class AsyncRelayCommandPageViewModel : SamplePageViewModel
911
{
10-
public class AsyncRelayCommandPageViewModel : SamplePageViewModel
12+
public AsyncRelayCommandPageViewModel()
1113
{
12-
public AsyncRelayCommandPageViewModel()
13-
{
14-
DownloadTextCommand = new AsyncRelayCommand(DownloadTextAsync);
15-
}
14+
DownloadTextCommand = new AsyncRelayCommand(DownloadTextAsync);
15+
}
1616

17-
public IAsyncRelayCommand DownloadTextCommand { get; }
17+
public IAsyncRelayCommand DownloadTextCommand { get; }
1818

19-
private async Task<string> DownloadTextAsync()
20-
{
21-
await Task.Delay(3000); // Simulate a web request
19+
private async Task<string> DownloadTextAsync()
20+
{
21+
await Task.Delay(3000); // Simulate a web request
2222

23-
return "Hello world!";
24-
}
23+
return "Hello world!";
2524
}
2625
}

samples/MvvmSample.Core/ViewModels/IocPageViewModel.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5-
namespace MvvmSample.Core.ViewModels
5+
namespace MvvmSample.Core.ViewModels;
6+
7+
public class IocPageViewModel : SamplePageViewModel
68
{
7-
public class IocPageViewModel : SamplePageViewModel
8-
{
9-
}
109
}

0 commit comments

Comments
 (0)