Skip to content

Commit b909482

Browse files
Use File-Scoped namespaces and Implicit Global Usings
1 parent 5eb77e2 commit b909482

File tree

10 files changed

+2136
-2145
lines changed

10 files changed

+2136
-2145
lines changed

.editorconfig

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,9 @@ csharp_space_between_square_brackets = false
253253
# https://docs.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/formatting-rules#wrap-options
254254
csharp_preserve_single_line_statements = false
255255
csharp_preserve_single_line_blocks = true
256+
# Namespace options
257+
# https://docs.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/formatting-rules#namespace-options
258+
csharp_style_namespace_declarations = file_scoped:warning
256259

257260
##########################################
258261
# .NET Naming Rules
@@ -452,4 +455,4 @@ dotnet_naming_rule.parameters_rule.severity = warning
452455
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
453456
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
454457
# OTHER DEALINGS IN THE SOFTWARE.
455-
##########################################
458+
##########################################

msbuild/props/SixLabors.Global.props

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<IsContinuousIntegration Condition="'$(CI)' == 'true'">true</IsContinuousIntegration>
2020
<IsCodeCoverage Condition="'$(codecov)' == 'true'">true</IsCodeCoverage>
2121
</PropertyGroup>
22-
22+
2323
<PropertyGroup Condition="'$(IsContinuousIntegration)'=='true'">
2424
<DefineConstants>$(DefineConstants);ENV_CI</DefineConstants>
2525
</PropertyGroup>
@@ -73,8 +73,13 @@
7373
<NullableContextOptions>disable</NullableContextOptions>
7474
<SuppressNETCoreSdkPreviewMessage>true</SuppressNETCoreSdkPreviewMessage>
7575
<CheckEolTargetFramework>false</CheckEolTargetFramework>
76+
<ImplicitUsings>true</ImplicitUsings>
7677
</PropertyGroup>
7778

79+
<ItemGroup Condition="'$(ImplicitUsings)'=='true'">
80+
<Using Include="SixLabors" />
81+
</ItemGroup>
82+
7883
<!-- Required restore feeds. -->
7984
<PropertyGroup>
8085
<RestoreSources>

msbuild/props/SixLabors.Tests.props

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
<PackageReference Include="xunit.runner.visualstudio"
2828
Version="2.4.3"
2929
IsImplicitlyDefined="true" />
30+
31+
<Using Include="Xunit" Condition="'$(ImplicitUsings)'=='true'"/>
3032
</ItemGroup>
3133

3234
</Project>

src/SharedInfrastructure/DebugGuard.cs

Lines changed: 236 additions & 236 deletions
Large diffs are not rendered by default.

src/SharedInfrastructure/Guard.Numeric.cs

Lines changed: 1082 additions & 1084 deletions
Large diffs are not rendered by default.

src/SharedInfrastructure/Guard.Numeric.tt.bak

Lines changed: 97 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -4,131 +4,129 @@
44
// Copyright (c) Six Labors.
55
// Licensed under the Six Labors Split License.
66

7-
using System;
87
using System.Runtime.CompilerServices;
98

109
namespace SixLabors
10+
11+
/// <summary>
12+
/// Provides methods to protect against invalid parameters.
13+
/// </summary>
14+
internal static partial class Guard
1115
{
12-
/// <summary>
13-
/// Provides methods to protect against invalid parameters.
14-
/// </summary>
15-
internal static partial class Guard
16-
{
1716
<#
1817
var types = new[] { "byte", "sbyte", "short", "ushort", "char", "int", "uint", "float", "long", "ulong", "double", "decimal" };
1918

2019
for (var i = 0; i < types.Length; i++)
2120
{
22-
if (i > 0) WriteLine("");
21+
if (i > 0) WriteLine("");
2322

24-
var T = types[i];
23+
var T = types[i];
2524
#>
26-
/// <summary>
27-
/// Ensures that the specified value is less than a maximum value.
28-
/// </summary>
29-
/// <param name="value">The target value, which should be validated.</param>
30-
/// <param name="max">The maximum value.</param>
31-
/// <param name="parameterName">The name of the parameter that is to be checked.</param>
32-
/// <exception cref="ArgumentException">
33-
/// <paramref name="value"/> is greater than the maximum value.
34-
/// </exception>
35-
[MethodImpl(MethodImplOptions.AggressiveInlining)]
36-
public static void MustBeLessThan(<#=T#> value, <#=T#> max, string parameterName)
25+
/// <summary>
26+
/// Ensures that the specified value is less than a maximum value.
27+
/// </summary>
28+
/// <param name="value">The target value, which should be validated.</param>
29+
/// <param name="max">The maximum value.</param>
30+
/// <param name="parameterName">The name of the parameter that is to be checked.</param>
31+
/// <exception cref="ArgumentException">
32+
/// <paramref name="value"/> is greater than the maximum value.
33+
/// </exception>
34+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
35+
public static void MustBeLessThan(<#=T#> value, <#=T#> max, string parameterName)
36+
{
37+
if (value < max)
3738
{
38-
if (value < max)
39-
{
40-
return;
41-
}
42-
43-
ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeLessThan(value, max, parameterName);
39+
return;
4440
}
4541

46-
/// <summary>
47-
/// Verifies that the specified value is less than or equal to a maximum value
48-
/// and throws an exception if it is not.
49-
/// </summary>
50-
/// <param name="value">The target value, which should be validated.</param>
51-
/// <param name="max">The maximum value.</param>
52-
/// <param name="parameterName">The name of the parameter that is to be checked.</param>
53-
/// <exception cref="ArgumentException">
54-
/// <paramref name="value"/> is greater than the maximum value.
55-
/// </exception>
56-
[MethodImpl(MethodImplOptions.AggressiveInlining)]
57-
public static void MustBeLessThanOrEqualTo(<#=T#> value, <#=T#> max, string parameterName)
58-
{
59-
if (value <= max)
60-
{
61-
return;
62-
}
42+
ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeLessThan(value, max, parameterName);
43+
}
6344

64-
ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeLessThanOrEqualTo(value, max, parameterName);
45+
/// <summary>
46+
/// Verifies that the specified value is less than or equal to a maximum value
47+
/// and throws an exception if it is not.
48+
/// </summary>
49+
/// <param name="value">The target value, which should be validated.</param>
50+
/// <param name="max">The maximum value.</param>
51+
/// <param name="parameterName">The name of the parameter that is to be checked.</param>
52+
/// <exception cref="ArgumentException">
53+
/// <paramref name="value"/> is greater than the maximum value.
54+
/// </exception>
55+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
56+
public static void MustBeLessThanOrEqualTo(<#=T#> value, <#=T#> max, string parameterName)
57+
{
58+
if (value <= max)
59+
{
60+
return;
6561
}
6662

67-
/// <summary>
68-
/// Verifies that the specified value is greater than a minimum value
69-
/// and throws an exception if it is not.
70-
/// </summary>
71-
/// <param name="value">The target value, which should be validated.</param>
72-
/// <param name="min">The minimum value.</param>
73-
/// <param name="parameterName">The name of the parameter that is to be checked.</param>
74-
/// <exception cref="ArgumentException">
75-
/// <paramref name="value"/> is less than the minimum value.
76-
/// </exception>
77-
[MethodImpl(MethodImplOptions.AggressiveInlining)]
78-
public static void MustBeGreaterThan(<#=T#> value, <#=T#> min, string parameterName)
79-
{
80-
if (value > min)
81-
{
82-
return;
83-
}
63+
ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeLessThanOrEqualTo(value, max, parameterName);
64+
}
8465

85-
ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeGreaterThan(value, min, parameterName);
66+
/// <summary>
67+
/// Verifies that the specified value is greater than a minimum value
68+
/// and throws an exception if it is not.
69+
/// </summary>
70+
/// <param name="value">The target value, which should be validated.</param>
71+
/// <param name="min">The minimum value.</param>
72+
/// <param name="parameterName">The name of the parameter that is to be checked.</param>
73+
/// <exception cref="ArgumentException">
74+
/// <paramref name="value"/> is less than the minimum value.
75+
/// </exception>
76+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
77+
public static void MustBeGreaterThan(<#=T#> value, <#=T#> min, string parameterName)
78+
{
79+
if (value > min)
80+
{
81+
return;
8682
}
8783

88-
/// <summary>
89-
/// Verifies that the specified value is greater than or equal to a minimum value
90-
/// and throws an exception if it is not.
91-
/// </summary>
92-
/// <param name="value">The target value, which should be validated.</param>
93-
/// <param name="min">The minimum value.</param>
94-
/// <param name="parameterName">The name of the parameter that is to be checked.</param>
95-
/// <exception cref="ArgumentException">
96-
/// <paramref name="value"/> is less than the minimum value.
97-
/// </exception>
98-
[MethodImpl(MethodImplOptions.AggressiveInlining)]
99-
public static void MustBeGreaterThanOrEqualTo(<#=T#> value, <#=T#> min, string parameterName)
100-
{
101-
if (value >= min)
102-
{
103-
return;
104-
}
84+
ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeGreaterThan(value, min, parameterName);
85+
}
10586

106-
ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeGreaterThanOrEqualTo(value, min, parameterName);
87+
/// <summary>
88+
/// Verifies that the specified value is greater than or equal to a minimum value
89+
/// and throws an exception if it is not.
90+
/// </summary>
91+
/// <param name="value">The target value, which should be validated.</param>
92+
/// <param name="min">The minimum value.</param>
93+
/// <param name="parameterName">The name of the parameter that is to be checked.</param>
94+
/// <exception cref="ArgumentException">
95+
/// <paramref name="value"/> is less than the minimum value.
96+
/// </exception>
97+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
98+
public static void MustBeGreaterThanOrEqualTo(<#=T#> value, <#=T#> min, string parameterName)
99+
{
100+
if (value >= min)
101+
{
102+
return;
107103
}
108104

109-
/// <summary>
110-
/// Verifies that the specified value is greater than or equal to a minimum value and less than
111-
/// or equal to a maximum value and throws an exception if it is not.
112-
/// </summary>
113-
/// <param name="value">The target value, which should be validated.</param>
114-
/// <param name="min">The minimum value.</param>
115-
/// <param name="max">The maximum value.</param>
116-
/// <param name="parameterName">The name of the parameter that is to be checked.</param>
117-
/// <exception cref="ArgumentException">
118-
/// <paramref name="value"/> is less than the minimum value of greater than the maximum value.
119-
/// </exception>
120-
[MethodImpl(MethodImplOptions.AggressiveInlining)]
121-
public static void MustBeBetweenOrEqualTo(<#=T#> value, <#=T#> min, <#=T#> max, string parameterName)
122-
{
123-
if (value >= min && value <= max)
124-
{
125-
return;
126-
}
105+
ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeGreaterThanOrEqualTo(value, min, parameterName);
106+
}
127107

128-
ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeBetweenOrEqualTo(value, min, max, parameterName);
108+
/// <summary>
109+
/// Verifies that the specified value is greater than or equal to a minimum value and less than
110+
/// or equal to a maximum value and throws an exception if it is not.
111+
/// </summary>
112+
/// <param name="value">The target value, which should be validated.</param>
113+
/// <param name="min">The minimum value.</param>
114+
/// <param name="max">The maximum value.</param>
115+
/// <param name="parameterName">The name of the parameter that is to be checked.</param>
116+
/// <exception cref="ArgumentException">
117+
/// <paramref name="value"/> is less than the minimum value of greater than the maximum value.
118+
/// </exception>
119+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
120+
public static void MustBeBetweenOrEqualTo(<#=T#> value, <#=T#> min, <#=T#> max, string parameterName)
121+
{
122+
if (value >= min && value <= max)
123+
{
124+
return;
129125
}
126+
127+
ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeBetweenOrEqualTo(value, min, max, parameterName);
128+
}
130129
<#
131130
}
132131
#>
133-
}
134132
}

0 commit comments

Comments
 (0)