Skip to content

Commit 4427b44

Browse files
authored
Merge pull request #75 from CommunityToolkit/dev/code-style-tweaks
Minor code style tweaks
2 parents 5309963 + 62d1245 commit 4427b44

37 files changed

+6734
-6813
lines changed

.git-blame-ignore-revs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,7 @@ eab4b9ed28c27db0c4194478eaa7c6e91664195d
33
93cb82a0d01bcf3feb2a79cc1eaf2d47b3c0cdd4
44

55
# Switch to file-scoped namespaces
6-
c176080d37953a2d811c81181192acc8695bbf73
6+
c176080d37953a2d811c81181192acc8695bbf73
7+
8+
# Fix leftover file-scoped namespaces
9+
0693d6c9647c8bea852de8f670e6c32516b18228

CommunityToolkit.Diagnostics/Extensions/ValueTypeExtensions.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ public static class ValueTypeExtensions
1818
/// </summary>
1919
private static ReadOnlySpan<byte> HexCharactersTable => new[]
2020
{
21-
(byte)'0', (byte)'1', (byte)'2', (byte)'3',
22-
(byte)'4', (byte)'5', (byte)'6', (byte)'7',
23-
(byte)'8', (byte)'9', (byte)'A', (byte)'B',
24-
(byte)'C', (byte)'D', (byte)'E', (byte)'F'
25-
};
21+
(byte)'0', (byte)'1', (byte)'2', (byte)'3',
22+
(byte)'4', (byte)'5', (byte)'6', (byte)'7',
23+
(byte)'8', (byte)'9', (byte)'A', (byte)'B',
24+
(byte)'C', (byte)'D', (byte)'E', (byte)'F'
25+
};
2626

2727
/// <summary>
2828
/// Returns a hexadecimal <see cref="string"/> representation of a given <typeparamref name="T"/> value, left-padded and ordered as big-endian.

CommunityToolkit.Diagnostics/Generated/Guard.Collection.g.cs

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

CommunityToolkit.Diagnostics/Generated/Guard.Collection.tt

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

CommunityToolkit.Diagnostics/Generated/Guard.Comparable.Numeric.g.cs

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

CommunityToolkit.Diagnostics/Generated/Guard.Comparable.Numeric.tt

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

CommunityToolkit.Diagnostics/Generated/ThrowHelper.Collection.g.cs

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

CommunityToolkit.Diagnostics/Generated/ThrowHelper.Collection.tt

Lines changed: 94 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -6,123 +6,118 @@ using System;
66
using System.Collections.Generic;
77
using System.Diagnostics.CodeAnalysis;
88

9-
namespace CommunityToolkit.Diagnostics
9+
namespace CommunityToolkit.Diagnostics;
10+
11+
/// <inheritdoc/>
12+
partial class Guard
1013
{
11-
/// <summary>
12-
/// Helper methods to verify conditions when running code.
13-
/// </summary>
14-
public static partial class Guard
14+
/// <inheritdoc/>
15+
partial class ThrowHelper
1516
{
16-
/// <summary>
17-
/// Helper methods to efficiently throw exceptions.
18-
/// </summary>
19-
private static partial class ThrowHelper
20-
{
2117
<#
2218
GenerateTextForItems(EnumerableTypes, item =>
2319
{
2420
#>
25-
/// <summary>
26-
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.IsEmpty{T}(T[],string)"/> (or an overload) fails.
27-
/// </summary>
28-
[DoesNotReturn]
29-
public static void ThrowArgumentExceptionForIsEmpty<T>(<#=item.Type#> <#=item.Name#>, string name)
30-
{
31-
throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(<#=item.Type#>).ToTypeString()}) must be empty, had a size of {AssertString(<#=item.Name#>.<#=item.Size#>)}.", name);
32-
}
21+
/// <summary>
22+
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.IsEmpty{T}(T[],string)"/> (or an overload) fails.
23+
/// </summary>
24+
[DoesNotReturn]
25+
public static void ThrowArgumentExceptionForIsEmpty<T>(<#=item.Type#> <#=item.Name#>, string name)
26+
{
27+
throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(<#=item.Type#>).ToTypeString()}) must be empty, had a size of {AssertString(<#=item.Name#>.<#=item.Size#>)}.", name);
28+
}
3329

34-
/// <summary>
35-
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeEqualTo{T}(T[],int,string)"/> (or an overload) fails.
36-
/// </summary>
37-
[DoesNotReturn]
38-
public static void ThrowArgumentExceptionForHasSizeEqualTo<T>(<#=item.Type#> <#=item.Name#>, int size, string name)
39-
{
40-
throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(<#=item.Type#>).ToTypeString()}) must have a size equal to {size}, had a size of {AssertString(<#=item.Name#>.<#=item.Size#>)}.", name);
41-
}
30+
/// <summary>
31+
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeEqualTo{T}(T[],int,string)"/> (or an overload) fails.
32+
/// </summary>
33+
[DoesNotReturn]
34+
public static void ThrowArgumentExceptionForHasSizeEqualTo<T>(<#=item.Type#> <#=item.Name#>, int size, string name)
35+
{
36+
throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(<#=item.Type#>).ToTypeString()}) must have a size equal to {size}, had a size of {AssertString(<#=item.Name#>.<#=item.Size#>)}.", name);
37+
}
4238

43-
/// <summary>
44-
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeNotEqualTo{T}(T[],int,string)"/> (or an overload) fails.
45-
/// </summary>
46-
[DoesNotReturn]
47-
public static void ThrowArgumentExceptionForHasSizeNotEqualTo<T>(<#=item.Type#> <#=item.Name#>, int size, string name)
48-
{
49-
throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(<#=item.Type#>).ToTypeString()}) must have a size not equal to {size}, had a size of {AssertString(<#=item.Name#>.<#=item.Size#>)}.", name);
50-
}
39+
/// <summary>
40+
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeNotEqualTo{T}(T[],int,string)"/> (or an overload) fails.
41+
/// </summary>
42+
[DoesNotReturn]
43+
public static void ThrowArgumentExceptionForHasSizeNotEqualTo<T>(<#=item.Type#> <#=item.Name#>, int size, string name)
44+
{
45+
throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(<#=item.Type#>).ToTypeString()}) must have a size not equal to {size}, had a size of {AssertString(<#=item.Name#>.<#=item.Size#>)}.", name);
46+
}
5147

52-
/// <summary>
53-
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeGreaterThan{T}(T[],int,string)"/> (or an overload) fails.
54-
/// </summary>
55-
[DoesNotReturn]
56-
public static void ThrowArgumentExceptionForHasSizeGreaterThan<T>(<#=item.Type#> <#=item.Name#>, int size, string name)
57-
{
58-
throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(<#=item.Type#>).ToTypeString()}) must have a size over {size}, had a size of {AssertString(<#=item.Name#>.<#=item.Size#>)}.", name);
59-
}
48+
/// <summary>
49+
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeGreaterThan{T}(T[],int,string)"/> (or an overload) fails.
50+
/// </summary>
51+
[DoesNotReturn]
52+
public static void ThrowArgumentExceptionForHasSizeGreaterThan<T>(<#=item.Type#> <#=item.Name#>, int size, string name)
53+
{
54+
throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(<#=item.Type#>).ToTypeString()}) must have a size over {size}, had a size of {AssertString(<#=item.Name#>.<#=item.Size#>)}.", name);
55+
}
6056

61-
/// <summary>
62-
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeGreaterThanOrEqualTo{T}(T[],int,string)"/> (or an overload) fails.
63-
/// </summary>
64-
[DoesNotReturn]
65-
public static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo<T>(<#=item.Type#> <#=item.Name#>, int size, string name)
66-
{
67-
throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(<#=item.Type#>).ToTypeString()}) must have a size of at least {size}, had a size of {AssertString(<#=item.Name#>.<#=item.Size#>)}.", name);
68-
}
57+
/// <summary>
58+
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeGreaterThanOrEqualTo{T}(T[],int,string)"/> (or an overload) fails.
59+
/// </summary>
60+
[DoesNotReturn]
61+
public static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo<T>(<#=item.Type#> <#=item.Name#>, int size, string name)
62+
{
63+
throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(<#=item.Type#>).ToTypeString()}) must have a size of at least {size}, had a size of {AssertString(<#=item.Name#>.<#=item.Size#>)}.", name);
64+
}
6965

70-
/// <summary>
71-
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeLessThan{T}(T[],int,string)"/> (or an overload) fails.
72-
/// </summary>
73-
[DoesNotReturn]
74-
public static void ThrowArgumentExceptionForHasSizeLessThan<T>(<#=item.Type#> <#=item.Name#>, int size, string name)
75-
{
76-
throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(<#=item.Type#>).ToTypeString()}) must have a size less than {size}, had a size of {AssertString(<#=item.Name#>.<#=item.Size#>)}.", name);
77-
}
66+
/// <summary>
67+
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeLessThan{T}(T[],int,string)"/> (or an overload) fails.
68+
/// </summary>
69+
[DoesNotReturn]
70+
public static void ThrowArgumentExceptionForHasSizeLessThan<T>(<#=item.Type#> <#=item.Name#>, int size, string name)
71+
{
72+
throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(<#=item.Type#>).ToTypeString()}) must have a size less than {size}, had a size of {AssertString(<#=item.Name#>.<#=item.Size#>)}.", name);
73+
}
7874

79-
/// <summary>
80-
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeLessThanOrEqualTo{T}(T[],int,string)"/> (or an overload) fails.
81-
/// </summary>
82-
[DoesNotReturn]
83-
public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo<T>(<#=item.Type#> <#=item.Name#>, int size, string name)
84-
{
85-
throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(<#=item.Type#>).ToTypeString()}) must have a size less than or equal to {size}, had a size of {AssertString(<#=item.Name#>.<#=item.Size#>)}.", name);
86-
}
75+
/// <summary>
76+
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeLessThanOrEqualTo{T}(T[],int,string)"/> (or an overload) fails.
77+
/// </summary>
78+
[DoesNotReturn]
79+
public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo<T>(<#=item.Type#> <#=item.Name#>, int size, string name)
80+
{
81+
throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(<#=item.Type#>).ToTypeString()}) must have a size less than or equal to {size}, had a size of {AssertString(<#=item.Name#>.<#=item.Size#>)}.", name);
82+
}
8783

88-
/// <summary>
89-
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeEqualTo{T}(T[],T[],string)"/> (or an overload) fails.
90-
/// </summary>
91-
[DoesNotReturn]
92-
public static void ThrowArgumentExceptionForHasSizeEqualTo<T>(<#=item.Type#> source, <#=item.DestinationType#> destination, string name)
93-
{
94-
throw new ArgumentException($"The source {AssertString(name)} ({typeof(<#=item.Type#>).ToTypeString()}) must have a size equal to {AssertString(destination.<#=item.Size#>)} (the destination), had a size of {AssertString(source.<#=item.Size#>)}.", name);
95-
}
84+
/// <summary>
85+
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeEqualTo{T}(T[],T[],string)"/> (or an overload) fails.
86+
/// </summary>
87+
[DoesNotReturn]
88+
public static void ThrowArgumentExceptionForHasSizeEqualTo<T>(<#=item.Type#> source, <#=item.DestinationType#> destination, string name)
89+
{
90+
throw new ArgumentException($"The source {AssertString(name)} ({typeof(<#=item.Type#>).ToTypeString()}) must have a size equal to {AssertString(destination.<#=item.Size#>)} (the destination), had a size of {AssertString(source.<#=item.Size#>)}.", name);
91+
}
9692

97-
/// <summary>
98-
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeLessThanOrEqualTo{T}(T[],T[],string)"/> (or an overload) fails.
99-
/// </summary>
100-
[DoesNotReturn]
101-
public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo<T>(<#=item.Type#> source, <#=item.DestinationType#> destination, string name)
102-
{
103-
throw new ArgumentException($"The source {AssertString(name)} ({typeof(<#=item.Type#>).ToTypeString()}) must have a size less than or equal to {AssertString(destination.<#=item.Size#>)} (the destination), had a size of {AssertString(source.<#=item.Size#>)}.", name);
104-
}
93+
/// <summary>
94+
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeLessThanOrEqualTo{T}(T[],T[],string)"/> (or an overload) fails.
95+
/// </summary>
96+
[DoesNotReturn]
97+
public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo<T>(<#=item.Type#> source, <#=item.DestinationType#> destination, string name)
98+
{
99+
throw new ArgumentException($"The source {AssertString(name)} ({typeof(<#=item.Type#>).ToTypeString()}) must have a size less than or equal to {AssertString(destination.<#=item.Size#>)} (the destination), had a size of {AssertString(source.<#=item.Size#>)}.", name);
100+
}
105101

106-
/// <summary>
107-
/// Throws an <see cref="ArgumentOutOfRangeException"/> when <see cref="Guard.IsInRangeFor{T}(int,T[],string)"/> (or an overload) fails.
108-
/// </summary>
109-
[DoesNotReturn]
110-
public static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor<T>(int index, <#=item.Type#> <#=item.Name#>, string name)
111-
{
112-
throw new ArgumentOutOfRangeException(name, index, $"Parameter {AssertString(name)} (int) must be in the range given by <0> and {AssertString(<#=item.Name#>.<#=item.Size#>)} to be a valid index for the target collection ({typeof(<#=item.Type#>).ToTypeString()}), was {AssertString(index)}.");
113-
}
102+
/// <summary>
103+
/// Throws an <see cref="ArgumentOutOfRangeException"/> when <see cref="Guard.IsInRangeFor{T}(int,T[],string)"/> (or an overload) fails.
104+
/// </summary>
105+
[DoesNotReturn]
106+
public static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor<T>(int index, <#=item.Type#> <#=item.Name#>, string name)
107+
{
108+
throw new ArgumentOutOfRangeException(name, index, $"Parameter {AssertString(name)} (int) must be in the range given by <0> and {AssertString(<#=item.Name#>.<#=item.Size#>)} to be a valid index for the target collection ({typeof(<#=item.Type#>).ToTypeString()}), was {AssertString(index)}.");
109+
}
114110

115-
/// <summary>
116-
/// Throws an <see cref="ArgumentOutOfRangeException"/> when <see cref="Guard.IsNotInRangeFor{T}(int,T[],string)"/> (or an overload) fails.
117-
/// </summary>
118-
[DoesNotReturn]
119-
public static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor<T>(int index, <#=item.Type#> <#=item.Name#>, string name)
120-
{
121-
throw new ArgumentOutOfRangeException(name, index, $"Parameter {AssertString(name)} (int) must not be in the range given by <0> and {AssertString(<#=item.Name#>.<#=item.Size#>)} to be an invalid index for the target collection ({typeof(<#=item.Type#>).ToTypeString()}), was {AssertString(index)}.");
122-
}
111+
/// <summary>
112+
/// Throws an <see cref="ArgumentOutOfRangeException"/> when <see cref="Guard.IsNotInRangeFor{T}(int,T[],string)"/> (or an overload) fails.
113+
/// </summary>
114+
[DoesNotReturn]
115+
public static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor<T>(int index, <#=item.Type#> <#=item.Name#>, string name)
116+
{
117+
throw new ArgumentOutOfRangeException(name, index, $"Parameter {AssertString(name)} (int) must not be in the range given by <0> and {AssertString(<#=item.Name#>.<#=item.Size#>)} to be an invalid index for the target collection ({typeof(<#=item.Type#>).ToTypeString()}), was {AssertString(index)}.");
118+
}
123119
<#
124120
});
125121
#>
126-
}
127122
}
128123
}

CommunityToolkit.Diagnostics/Guard.Comparable.Generic.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@
77

88
namespace CommunityToolkit.Diagnostics;
99

10-
/// <summary>
11-
/// Helper methods to verify conditions when running code.
12-
/// </summary>
13-
public static partial class Guard
10+
/// <inheritdoc/>
11+
partial class Guard
1412
{
1513
/// <summary>
1614
/// Asserts that the input value is <see langword="default"/>.

CommunityToolkit.Diagnostics/Guard.Comparable.Numeric.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@
77

88
namespace CommunityToolkit.Diagnostics;
99

10-
/// <summary>
11-
/// Helper methods to verify conditions when running code.
12-
/// </summary>
13-
public static partial class Guard
10+
/// <inheritdoc/>
11+
partial class Guard
1412
{
1513
/// <summary>
1614
/// Asserts that the input value must be within a given distance from a specified value.

0 commit comments

Comments
 (0)