Skip to content

Commit df0bd55

Browse files
Style only changes.
1 parent 11c5c82 commit df0bd55

18 files changed

Lines changed: 286 additions & 247 deletions

.editorconfig

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ dotnet_style_allow_statement_immediately_after_block_experimental = false
7272
#### C# Coding Conventions ####
7373

7474
# var preferences
75-
csharp_style_var_elsewhere = false
76-
csharp_style_var_for_built_in_types = false
75+
csharp_style_var_elsewhere = false:silent
76+
csharp_style_var_for_built_in_types = false:silent
7777
csharp_style_var_when_type_is_apparent = true:suggestion
7878

7979
# Expression-bodied members
@@ -97,7 +97,7 @@ csharp_style_prefer_switch_expression = true:suggestion
9797
csharp_style_conditional_delegate_call = true:warning
9898

9999
# Modifier preferences
100-
csharp_prefer_static_local_function = true
100+
csharp_prefer_static_local_function = true:suggestion
101101
csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async
102102

103103
# Code-block preferences
@@ -115,16 +115,16 @@ csharp_style_prefer_index_operator = true:silent
115115
csharp_style_prefer_null_check_over_type_check = true:warning
116116
csharp_style_prefer_range_operator = true:silent
117117
csharp_style_throw_expression = true:warning
118-
csharp_style_unused_value_assignment_preference = discard_variable:suggestion
118+
csharp_style_unused_value_assignment_preference = discard_variable:silent
119119
csharp_style_unused_value_expression_statement_preference = discard_variable:silent
120120

121121
# 'using' directive preferences
122122
csharp_using_directive_placement = outside_namespace:warning
123123

124124
# New line preferences
125125
csharp_style_allow_blank_line_after_colon_in_constructor_initializer_experimental = false:warning
126-
csharp_style_allow_blank_lines_between_consecutive_braces_experimental = true
127-
csharp_style_allow_embedded_statements_on_same_line_experimental = true
126+
csharp_style_allow_blank_lines_between_consecutive_braces_experimental = true:silent
127+
csharp_style_allow_embedded_statements_on_same_line_experimental = true:silent
128128

129129
#### C# Formatting Rules ####
130130

@@ -225,6 +225,12 @@ dotnet_diagnostic.SYSLIB1045.severity = silent
225225

226226
# IDE0055: Fix formatting
227227
dotnet_diagnostic.IDE0055.severity = silent
228+
csharp_prefer_system_threading_lock = true:suggestion
229+
csharp_prefer_static_anonymous_function = true:warning
230+
csharp_style_prefer_readonly_struct = true:error
231+
csharp_style_prefer_readonly_struct_member = true:suggestion
232+
csharp_style_allow_blank_line_after_token_in_conditional_expression_experimental = false:error
233+
csharp_style_allow_blank_line_after_token_in_arrow_expression_clause_experimental = false:error
228234

229235
[*.{cs,vb}]
230236
dotnet_style_operator_placement_when_wrapping = beginning_of_line
@@ -252,4 +258,22 @@ dotnet_style_prefer_simplified_interpolation = true:suggestion
252258
dotnet_style_namespace_match_folder = true:suggestion
253259
dotnet_diagnostic.CA1510.severity = silent
254260
dotnet_diagnostic.CA1512.severity = silent
255-
dotnet_diagnostic.CA1863.severity = none
261+
dotnet_diagnostic.CA1863.severity = none
262+
dotnet_diagnostic.IDE0056.severity = silent
263+
dotnet_diagnostic.IDE0057.severity = silent
264+
dotnet_diagnostic.IDE0058.severity = silent
265+
dotnet_style_prefer_collection_expression = when_types_loosely_match:suggestion
266+
dotnet_style_readonly_field = true:suggestion
267+
dotnet_style_predefined_type_for_locals_parameters_members = true:warning
268+
dotnet_style_predefined_type_for_member_access = true:warning
269+
dotnet_style_require_accessibility_modifiers = for_non_interface_members:silent
270+
dotnet_style_allow_multiple_blank_lines_experimental = true:silent
271+
dotnet_style_allow_statement_immediately_after_block_experimental = false:silent
272+
dotnet_code_quality_unused_parameters = all:suggestion
273+
dotnet_style_parentheses_in_arithmetic_binary_operators = never_if_unnecessary:suggestion
274+
dotnet_style_parentheses_in_other_binary_operators = never_if_unnecessary:suggestion
275+
dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:suggestion
276+
dotnet_style_parentheses_in_other_operators = never_if_unnecessary:suggestion
277+
dotnet_style_qualification_for_field = false:silent
278+
dotnet_style_qualification_for_method = false:suggestion
279+
dotnet_style_qualification_for_event = false:suggestion

Source/EnumValue.cs

Lines changed: 42 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,11 @@ public static IReadOnlyList<TEnum> Values
6060
internal static ConcurrentDictionary<TEnum, IReadOnlyList<Attribute>> Attributes
6161
=> LazyInitializer.EnsureInitialized(ref _attributes)!;
6262

63-
static Func<TEnum, string> GetEnumNameDelegate()
63+
private static Func<TEnum, string> GetEnumNameDelegate()
6464
{
65-
var tResult = typeof(string);
66-
var eValue = Parameter(typeof(TEnum), "value"); // (TEnum value)
65+
Type tResult = typeof(string);
66+
ParameterExpression eValue
67+
= Parameter(typeof(TEnum), "value"); // (TEnum value)
6768

6869
return Lambda<Func<TEnum, string>>(
6970
Switch(tResult, eValue,
@@ -85,12 +86,12 @@ internal static Func<TEnum, string> NameLookup
8586
GetEnumNameDelegate)!;
8687
internal static Func<string, ValueLookupResult> GetEnumTryParseDelegate()
8788
{
88-
var valueParam = Parameter(typeof(string), "value");
89-
var lengthParam = Variable(typeof(int), "length");
90-
var defaultExpression = CreateNewTuple(false, default!);
91-
var enumValues = Values.Select(v => (value: v, name: string.Intern(v.ToString())));
92-
var nameGroups = enumValues.GroupBy(v => v.name.Length).OrderBy(g => g.Key);
93-
var lengthCheckCases = nameGroups.Select(group =>
89+
ParameterExpression valueParam = Parameter(typeof(string), "value");
90+
ParameterExpression lengthParam = Variable(typeof(int), "length");
91+
Expression defaultExpression = CreateNewTuple(false, default!);
92+
IEnumerable<(TEnum value, string name)> enumValues = Values.Select(v => (value: v, name: string.Intern(v.ToString())));
93+
IOrderedEnumerable<IGrouping<int, (TEnum value, string name)>> nameGroups = enumValues.GroupBy(v => v.name.Length).OrderBy(g => g.Key);
94+
SwitchCase[] lengthCheckCases = nameGroups.Select(group =>
9495
SwitchCase(
9596
Switch(
9697
valueParam,
@@ -150,31 +151,32 @@ internal static IReadOnlyDictionary<string, TEnum> IgnoreCaseLookup
150151
{
151152
// If the enum has duplicate values, we want to use the first one.
152153
var result = new Dictionary<string, TEnum>(StringComparer.OrdinalIgnoreCase);
153-
foreach (var e in Values)
154+
foreach (TEnum e in Values)
154155
{
155-
var v = Enum.GetName(typeof(TEnum), e)!;
156+
string v = Enum.GetName(typeof(TEnum), e)!;
156157
if (result.ContainsKey(v)) continue;
157158
result[v] = e;
158159
}
160+
159161
return result;
160162
})!;
161163

162-
static Entry[]?[] CreateLookup()
164+
private static Entry[]?[] CreateLookup()
163165
{
164-
var longest = 0;
166+
int longest = 0;
165167
var d = new Dictionary<int, List<Entry>>();
166168

167-
foreach (var e in Values)
169+
foreach (TEnum e in Values)
168170
{
169-
var n = string.Intern(e.ToString());
170-
var len = n.Length;
171+
string n = string.Intern(e.ToString());
172+
int len = n.Length;
171173
if (len > longest) longest = len;
172-
if (!d.TryGetValue(len, out var v)) d.Add(len, v = []);
174+
if (!d.TryGetValue(len, out List<Entry>? v)) d.Add(len, v = []);
173175
v.Add(new(n, e));
174176
}
175177

176178
var result = new Entry[]?[longest + 1];
177-
foreach (var i in d.Keys)
179+
foreach (int i in d.Keys)
178180
result[i] = [.. d[i].OrderBy(v => v.Name)];
179181

180182
return result;
@@ -194,10 +196,10 @@ public Entry(string name, TEnum value)
194196
public static int Find(Span<Entry> span, ReadOnlySpan<char> name, StringComparison sc)
195197
{
196198
// Small enough? Just brute force the index.
197-
var len = span.Length;
199+
int len = span.Length;
198200
if (len < 12)
199201
{
200-
for (var i = 0; i < len; i++)
202+
for (int i = 0; i < len; i++)
201203
{
202204
ref Entry e = ref span[i];
203205
if (name.Equals(e.Name, sc))
@@ -214,12 +216,12 @@ public static int Find(Span<Entry> span, ReadOnlySpan<char> name, StringComparis
214216
while (left <= right)
215217
{
216218
int middle = left + (right - left) / 2;
217-
var middleKey = span[middle].Name.AsSpan();
219+
ReadOnlySpan<char> middleKey = span[middle].Name.AsSpan();
218220

219221
if (right - left < 4 && name.Equals(middleKey, sc))
220222
return middle;
221223

222-
var comparison = name.CompareTo(middleKey, sc);
224+
int comparison = name.CompareTo(middleKey, sc);
223225
if (comparison < 0)
224226
right = middle - 1;
225227
else if (comparison > 0)
@@ -326,7 +328,7 @@ public override bool Equals(object? obj)
326328
/// </summary>
327329
public static implicit operator EnumValue<TEnum>(string value) => new(value);
328330

329-
static class Underlying<T>
331+
private static class Underlying<T>
330332
where T : notnull
331333
{
332334
public static readonly Dictionary<T, TEnum> Map = [];
@@ -336,7 +338,7 @@ static Underlying()
336338
{
337339
if (typeof(T) != UnderlyingType) return;
338340

339-
foreach (var e in Values)
341+
foreach (TEnum e in Values)
340342
{
341343
var i = (T)System.Convert.ChangeType(e, typeof(T));
342344
Map.Add(i, e);
@@ -361,7 +363,7 @@ public static bool TryGetValue<T>(T value, out TEnum e)
361363

362364
private string GetDebuggerDisplay()
363365
{
364-
var eType = typeof(TEnum);
366+
Type eType = typeof(TEnum);
365367
return $"{eType.Name}.{Value} [EnumValue<{eType.FullName}>]";
366368
}
367369
}
@@ -481,7 +483,7 @@ public static implicit operator EnumValueCaseIgnored<TEnum>(string value)
481483

482484
private string GetDebuggerDisplay()
483485
{
484-
var eType = typeof(TEnum);
486+
Type eType = typeof(TEnum);
485487
return $"{eType.Name}.{ToString()} [EnumValueCaseIgnored<{eType.FullName}>]";
486488
}
487489
}
@@ -501,7 +503,7 @@ public static class EnumValue
501503
public static TEnum Parse<TEnum>(string value)
502504
where TEnum : notnull, Enum
503505
{
504-
var (success, result) = EnumValue<TEnum>.ValueLookup(value);
506+
(bool success, TEnum result) = EnumValue<TEnum>.ValueLookup(value);
505507
return success ? result
506508
: throw new ArgumentException(string.Format(NotFoundMessage, value), nameof(value));
507509
}
@@ -511,7 +513,7 @@ public static TEnum Parse<TEnum>(string value)
511513
public static bool TryParse<TEnum>(string value, out TEnum e)
512514
where TEnum : notnull, Enum
513515
{
514-
var result = EnumValue<TEnum>.ValueLookup(value);
516+
EnumValue<TEnum>.ValueLookupResult result = EnumValue<TEnum>.ValueLookup(value);
515517
e = result.Value;
516518
return result.Success;
517519
}
@@ -523,15 +525,15 @@ public static bool TryParse<TEnum>(string value, out TEnum e)
523525
[MethodImpl(MethodImplOptions.AggressiveInlining)]
524526
public static TEnum Parse<TEnum>(StringSegment value)
525527
where TEnum : notnull, Enum
526-
=> TryParse<TEnum>(value, false, out var e) ? e
528+
=> TryParse<TEnum>(value, false, out TEnum? e) ? e
527529
: throw new ArgumentException(string.Format(NotFoundMessage, value), nameof(value));
528530

529531
/// <inheritdoc cref="TryParse{TEnum}(StringSegment, bool, out TEnum)"/>
530532
[MethodImpl(MethodImplOptions.AggressiveInlining)]
531533
public static TEnum Parse<TEnum>(string value, bool ignoreCase)
532534
where TEnum : notnull, Enum
533535
=> ignoreCase
534-
? EnumValue<TEnum>.IgnoreCaseLookup.TryGetValue(value, out var e) ? e
536+
? EnumValue<TEnum>.IgnoreCaseLookup.TryGetValue(value, out TEnum? e) ? e
535537
: throw new ArgumentException(string.Format(NotFoundMessage, value), nameof(value))
536538
: Parse<TEnum>(value);
537539

@@ -540,10 +542,10 @@ public static TEnum Parse<TEnum>(string value, bool ignoreCase)
540542
public static TEnum Parse<TEnum>(StringSegment value, bool ignoreCase)
541543
where TEnum : notnull, Enum
542544
{
543-
var buffer = value.Buffer ?? throw new ArgumentNullException(nameof(value));
545+
string buffer = value.Buffer ?? throw new ArgumentNullException(nameof(value));
544546
return value.Length == buffer.Length
545547
? Parse<TEnum>(value.Buffer, ignoreCase)
546-
: TryParse<TEnum>(value, ignoreCase, out var e)
548+
: TryParse<TEnum>(value, ignoreCase, out TEnum? e)
547549
? e : throw new ArgumentException(string.Format(NotFoundMessage, value), nameof(value));
548550
}
549551

@@ -578,27 +580,27 @@ public static bool TryParseIgnoreCase<TEnum>(string name, out TEnum e)
578580
public static bool TryParse<TEnum>(StringSegment name, bool ignoreCase, out TEnum e)
579581
where TEnum : notnull, Enum
580582
{
581-
var len = name.Length;
583+
int len = name.Length;
582584
if (len == 0) goto notFound;
583585

584586
// If this is a string, use the optimized version.
585587
string buffer = name.Buffer!;
586588
if (buffer.Length == len)
587589
return TryParse(buffer, ignoreCase, out e);
588590

589-
var lookup = EnumValue<TEnum>.Lookup;
591+
EnumValue<TEnum>.Entry[]?[] lookup = EnumValue<TEnum>.Lookup;
590592
if (len >= lookup.Length) goto notFound;
591593

592-
var r = lookup[len];
594+
EnumValue<TEnum>.Entry[]? r = lookup[len];
593595
if (r is null) goto notFound;
594596
Debug.Assert(r.Length != 0);
595597

596-
var sc = ignoreCase
598+
StringComparison sc = ignoreCase
597599
? StringComparison.OrdinalIgnoreCase
598600
: StringComparison.Ordinal;
599601

600-
var span = r.AsSpan();
601-
var index = EnumValue<TEnum>.Entry.Find(span, name, sc);
602+
Span<EnumValue<TEnum>.Entry> span = r.AsSpan();
603+
int index = EnumValue<TEnum>.Entry.Find(span, name, sc);
602604
if (index != -1)
603605
{
604606
e = span[index].Value;
@@ -641,8 +643,8 @@ public static IReadOnlyList<Attribute> GetAttributes<TEnum>(this TEnum value)
641643

642644
static IReadOnlyList<Attribute> GetAttributesCore(TEnum value)
643645
{
644-
var memInfo = typeof(TEnum).GetMember(value.GetName());
645-
var attributes = memInfo[0].GetCustomAttributes(false);
646+
MemberInfo[] memInfo = typeof(TEnum).GetMember(value.GetName());
647+
object[] attributes = memInfo[0].GetCustomAttributes(false);
646648
return attributes.Length is 0
647649
? Array.Empty<Attribute>()
648650
: Array.AsReadOnly(attributes.OfType<Attribute>().ToArray());

Source/Extensions.Equals.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public static partial class TextExtensions
1212
public static bool Equals(this ReadOnlySpan<char> source, StringSegment other, StringComparison comparisonType)
1313
{
1414
if (!other.HasValue) return false;
15-
var len = source.Length;
15+
int len = source.Length;
1616
return len == other.Length && len switch
1717
{
1818
0 => true,
@@ -25,7 +25,7 @@ public static bool Equals(this ReadOnlySpan<char> source, StringSegment other, S
2525
public static bool Equals(this Span<char> source, StringSegment other, StringComparison comparisonType)
2626
{
2727
if (!other.HasValue) return false;
28-
var len = source.Length;
28+
int len = source.Length;
2929
return len == other.Length && len switch
3030
{
3131
0 => true,
@@ -37,7 +37,7 @@ public static bool Equals(this Span<char> source, StringSegment other, StringCom
3737
/// <inheritdoc cref="Equals(ReadOnlySpan{char}, StringSegment, StringComparison)"/>
3838
public static bool Equals(this Span<char> source, ReadOnlySpan<char> other, StringComparison comparisonType)
3939
{
40-
var len = source.Length;
40+
int len = source.Length;
4141
return len == other.Length && len switch
4242
{
4343
0 => true,
@@ -50,7 +50,7 @@ public static bool Equals(this Span<char> source, ReadOnlySpan<char> other, Stri
5050
public static bool Equals(this string? source, ReadOnlySpan<char> other, StringComparison comparisonType)
5151
{
5252
if (source is null) return false;
53-
var len = source.Length;
53+
int len = source.Length;
5454
return len == other.Length && len switch
5555
{
5656
0 => true,
@@ -63,7 +63,7 @@ public static bool Equals(this string? source, ReadOnlySpan<char> other, StringC
6363
public static bool Equals(this StringSegment source, ReadOnlySpan<char> other, StringComparison comparisonType)
6464
{
6565
if (!source.HasValue) return false;
66-
var len = source.Length;
66+
int len = source.Length;
6767
return len == other.Length && len switch
6868
{
6969
0 => true,
@@ -136,12 +136,12 @@ public static bool TrimmedEquals(this string? source, ReadOnlySpan<char> other,
136136
/// <inheritdoc cref="TrimmedEquals(string?, StringSegment, ReadOnlySpan{char}, StringComparison)"/>
137137
public static bool TrimmedEquals(this string? source, StringSegment other, char trimChar, StringComparison comparisonType = StringComparison.Ordinal)
138138
{
139-
var otherHasValue = !other.HasValue;
139+
bool otherHasValue = !other.HasValue;
140140
if (source is null) return otherHasValue;
141141
if (otherHasValue) return false;
142142
int slen = source.Length, olen = other.Length;
143143
if (slen < olen) return false;
144-
var span = source.AsSpan().Trim(trimChar);
144+
ReadOnlySpan<char> span = source.AsSpan().Trim(trimChar);
145145
slen = span.Length;
146146
return slen == olen && slen switch
147147
{
@@ -193,7 +193,7 @@ public static bool TrimmedEquals(this string? source, StringSegment other, ReadO
193193
if (!other.HasValue) return false;
194194
int slen = source.Length, olen = other.Length;
195195
if (slen < olen) return false;
196-
var trimmed = source.AsSpan().Trim(trimChars);
196+
ReadOnlySpan<char> trimmed = source.AsSpan().Trim(trimChars);
197197
slen = trimmed.Length;
198198
return slen == olen && slen switch
199199
{

0 commit comments

Comments
 (0)