Skip to content

Commit 16d0fde

Browse files
committed
small refactor
1 parent a2aff80 commit 16d0fde

File tree

2 files changed

+20
-23
lines changed

2 files changed

+20
-23
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// Copyright © WireMock.Net
22

3-
using JetBrains.Annotations;
43
using System.Collections.Generic;
54

65
namespace WireMock.Handlers;
@@ -21,91 +20,91 @@ public interface IFileSystemHandler
2120
/// </summary>
2221
/// <param name="path">The path.</param>
2322
/// <returns>true if path refers to an existing directory; false if the directory does not exist or an error occurs when trying to determine if the specified directory exists.</returns>
24-
bool FolderExists([NotNull] string path);
23+
bool FolderExists(string path);
2524

2625
/// <summary>
2726
/// Creates all directories and subdirectories in the specified path unless they already exist.
2827
/// </summary>
2928
/// <param name="path">The path.</param>
30-
void CreateFolder([NotNull] string path);
29+
void CreateFolder(string path);
3130

3231
/// <summary>
3332
/// Returns an enumerable collection of file names in a specified path.
3433
/// </summary>
3534
/// <param name="path">The path.</param>
36-
/// <param name="includeSubdirectories">A value indicating whether subdirectories should also included when enumerating files.</param>
35+
/// <param name="includeSubdirectories">A value indicating whether subdirectories should also be included when enumerating files.</param>
3736
/// <returns>An enumerable collection of the full names (including paths) for the files in the directory (and optionally subdirectories) specified by path.</returns>
38-
IEnumerable<string> EnumerateFiles([NotNull] string path, bool includeSubdirectories);
37+
IEnumerable<string> EnumerateFiles(string path, bool includeSubdirectories);
3938

4039
/// <summary>
4140
/// Read a static mapping file as text.
4241
/// </summary>
4342
/// <param name="path">The path (folder + filename with .json extension).</param>
4443
/// <returns>The file content as text.</returns>
45-
string ReadMappingFile([NotNull] string path);
44+
string ReadMappingFile(string path);
4645

4746
/// <summary>
4847
/// Write the static mapping file.
4948
/// </summary>
5049
/// <param name="path">The path (folder + filename with .json extension).</param>
5150
/// <param name="text">The text.</param>
52-
void WriteMappingFile([NotNull] string path, [NotNull] string text);
51+
void WriteMappingFile(string path, string text);
5352

5453
/// <summary>
5554
/// Read a response body file as byte[].
5655
/// </summary>
5756
/// <param name="path">The path or filename from the file to read.</param>
5857
/// <returns>The file content as bytes.</returns>
59-
byte[] ReadResponseBodyAsFile([NotNull] string path);
58+
byte[] ReadResponseBodyAsFile(string path);
6059

6160
/// <summary>
6261
/// Read a response body file as text.
6362
/// </summary>
6463
/// <param name="path">The path or filename from the file to read.</param>
6564
/// <returns>The file content as text.</returns>
66-
string ReadResponseBodyAsString([NotNull] string path);
65+
string ReadResponseBodyAsString(string path);
6766

6867
/// <summary>
6968
/// Delete a file.
7069
/// </summary>
7170
/// <param name="filename">The filename.</param>
72-
void DeleteFile([NotNull] string filename);
71+
void DeleteFile(string filename);
7372

7473
/// <summary>
7574
/// Determines whether the given path refers to an existing file on disk.
7675
/// </summary>
7776
/// <param name="filename">The filename.</param>
7877
/// <returns>true if path refers to an existing file; false if the file does not exist.</returns>
79-
bool FileExists([NotNull] string filename);
78+
bool FileExists(string filename);
8079

8180
/// <summary>
8281
/// Write a file.
8382
/// </summary>
8483
/// <param name="filename">The filename.</param>
8584
/// <param name="bytes">The bytes.</param>
86-
void WriteFile([NotNull] string filename, [NotNull] byte[] bytes);
85+
void WriteFile(string filename, byte[] bytes);
8786

8887
/// <summary>
8988
/// Write a file.
9089
/// </summary>
9190
/// <param name="folder">The folder.</param>
9291
/// <param name="filename">The filename.</param>
9392
/// <param name="bytes">The bytes.</param>
94-
void WriteFile([NotNull] string folder, [NotNull] string filename, [NotNull] byte[] bytes);
93+
void WriteFile(string folder, string filename, byte[] bytes);
9594

9695
/// <summary>
9796
/// Read a file as bytes.
9897
/// </summary>
9998
/// <param name="filename">The filename.</param>
10099
/// <returns>The file content as bytes.</returns>
101-
byte[] ReadFile([NotNull] string filename);
100+
byte[] ReadFile(string filename);
102101

103102
/// <summary>
104103
/// Read a file as string.
105104
/// </summary>
106105
/// <param name="filename">The filename.</param>
107106
/// <returns>The file content as a string.</returns>
108-
string ReadFileAsString([NotNull] string filename);
107+
string ReadFileAsString(string filename);
109108

110109
/// <summary>
111110
/// Gets the folder where the unmatched requests should be stored. For local file system, this would be `{CurrentFolder}/requests/unmatched`.
@@ -114,9 +113,9 @@ public interface IFileSystemHandler
114113
string GetUnmatchedRequestsFolder();
115114

116115
/// <summary>
117-
/// Write a unmatched request to the Unmatched RequestsFolder.
116+
/// Write an unmatched request to the Unmatched RequestsFolder.
118117
/// </summary>
119118
/// <param name="filename">The filename.</param>
120119
/// <param name="text">The text.</param>
121-
void WriteUnmatchedRequest([NotNull] string filename, [NotNull] string text);
120+
void WriteUnmatchedRequest(string filename, string text);
122121
}

src/WireMock.Net/Json/JObjectExtensions.cs

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Copyright © WireMock.Net
22

3-
// Copied from https://github.com/Handlebars-Net/Handlebars.Net.Helpers/blob/master/src/Handlebars.Net.Helpers.DynamicLinq
3+
// Copied from https://github.com/Handlebars-Net/Handlebars.Net.Helpers/blob/master/src/Handlebars.Net.Helpers.DynamicLinq which is copied from https://github.com/StefH/JsonConverter
44

55
using System;
66
using System.Collections;
@@ -14,9 +14,7 @@ namespace WireMock.Json;
1414

1515
internal static class JObjectExtensions
1616
{
17-
private class JTokenResolvers : Dictionary<JTokenType, Func<JToken, DynamicJsonClassOptions?, object?>>
18-
{
19-
}
17+
private class JTokenResolvers : Dictionary<JTokenType, Func<JToken, DynamicJsonClassOptions?, object?>>;
2018

2119
private static readonly JTokenResolvers Resolvers = new()
2220
{
@@ -180,7 +178,7 @@ private static IEnumerable ConvertJTokenArray(JToken arg, DynamicJsonClassOption
180178
private static IEnumerable ConvertToTypedArray(IEnumerable<object?> src, Type newType)
181179
{
182180
var method = ConvertToTypedArrayGenericMethod.MakeGenericMethod(newType);
183-
return (IEnumerable)method.Invoke(null, new object[] { src })!;
181+
return (IEnumerable)method.Invoke(null, [src])!;
184182
}
185183

186184
private static readonly MethodInfo ConvertToTypedArrayGenericMethod = typeof(JObjectExtensions).GetMethod(nameof(ConvertToTypedArrayGeneric), BindingFlags.NonPublic | BindingFlags.Static)!;
@@ -193,7 +191,7 @@ private static T[] ConvertToTypedArrayGeneric<T>(IEnumerable<object> src)
193191
public static DynamicClass CreateInstance(IList<DynamicPropertyWithValue> dynamicPropertiesWithValue, bool createParameterCtor = true)
194192
{
195193
var type = DynamicClassFactory.CreateType(dynamicPropertiesWithValue.Cast<DynamicProperty>().ToArray(), createParameterCtor);
196-
var dynamicClass = (DynamicClass)Activator.CreateInstance(type);
194+
var dynamicClass = (DynamicClass)Activator.CreateInstance(type)!;
197195
foreach (var dynamicPropertyWithValue in dynamicPropertiesWithValue.Where(p => p.Value != null))
198196
{
199197
dynamicClass.SetDynamicPropertyValue(dynamicPropertyWithValue.Name, dynamicPropertyWithValue.Value!);

0 commit comments

Comments
 (0)