Skip to content

Commit 6b90166

Browse files
authored
Remove ToStringFastWithMetadata when it's not needed (#176)
1 parent 6b33614 commit 6b90166

File tree

46 files changed

+57
-199
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+57
-199
lines changed

src/NetEscapades.EnumGenerators/SourceGenerationHelper.cs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -167,17 +167,21 @@ public static string ToStringFast(this
167167
""").Append(fullyQualifiedName).Append(
168168
"""
169169
value, bool useMetadataAttributes)
170-
=> useMetadataAttributes ? value.ToStringFastWithMetadata() : value.ToStringFast();
171-
172-
private static string ToStringFastWithMetadata(this
173-
""").Append(fullyQualifiedName).Append(
174-
"""
175-
value)
176-
=>
177170
""");
171+
178172
if (hasMetadataNames)
179173
{
180174
sb.Append(
175+
"""
176+
177+
=> useMetadataAttributes ? value.ToStringFastWithMetadata() : value.ToStringFast();
178+
179+
private static string ToStringFastWithMetadata(this
180+
""").Append(fullyQualifiedName).Append(
181+
"""
182+
value)
183+
=>
184+
""").Append(
181185
"""
182186
value switch
183187
{
@@ -228,7 +232,11 @@ private static string ToStringFastWithMetadata(this
228232
}
229233
else
230234
{
231-
sb.Append("value.ToStringFast();");
235+
sb.Append(
236+
"""
237+
238+
=> value.ToStringFast();
239+
""");
232240
}
233241
}
234242

tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsForFlagsEnum_Params.verified.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//------------------------------------------------------------------------------
1+
//------------------------------------------------------------------------------
22
// <auto-generated>
33
// This code was generated by the NetEscapades.EnumGenerators source generator
44
//
@@ -52,9 +52,6 @@ namespace MyTestNameSpace
5252
/// If <see langword="false"/>, always uses the name of the member, the same as if <c>ToString()</c> was called.</param>
5353
/// <returns>The string representation of the value</returns>
5454
public static string ToStringFast(this global::MyTestNameSpace.MyEnum value, bool useMetadataAttributes)
55-
=> useMetadataAttributes ? value.ToStringFastWithMetadata() : value.ToStringFast();
56-
57-
private static string ToStringFastWithMetadata(this global::MyTestNameSpace.MyEnum value)
5855
=> value.ToStringFast();
5956

6057
/// <summary>

tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsInChildNamespace.verified.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//------------------------------------------------------------------------------
1+
//------------------------------------------------------------------------------
22
// <auto-generated>
33
// This code was generated by the NetEscapades.EnumGenerators source generator
44
//
@@ -51,9 +51,6 @@ namespace MyTestNameSpace
5151
/// If <see langword="false"/>, always uses the name of the member, the same as if <c>ToString()</c> was called.</param>
5252
/// <returns>The string representation of the value</returns>
5353
public static string ToStringFast(this global::MyTestNameSpace.MyEnum value, bool useMetadataAttributes)
54-
=> useMetadataAttributes ? value.ToStringFastWithMetadata() : value.ToStringFast();
55-
56-
private static string ToStringFastWithMetadata(this global::MyTestNameSpace.MyEnum value)
5754
=> value.ToStringFast();
5855

5956
/// <summary>

tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsInGlobalNamespace.verified.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//------------------------------------------------------------------------------
1+
//------------------------------------------------------------------------------
22
// <auto-generated>
33
// This code was generated by the NetEscapades.EnumGenerators source generator
44
//
@@ -49,9 +49,6 @@
4949
/// If <see langword="false"/>, always uses the name of the member, the same as if <c>ToString()</c> was called.</param>
5050
/// <returns>The string representation of the value</returns>
5151
public static string ToStringFast(this global::MyEnum value, bool useMetadataAttributes)
52-
=> useMetadataAttributes ? value.ToStringFastWithMetadata() : value.ToStringFast();
53-
54-
private static string ToStringFastWithMetadata(this global::MyEnum value)
5552
=> value.ToStringFast();
5653

5754
/// <summary>

tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsInGlobalNamespace_ForceExtensions.verified.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,6 @@
4949
/// If <see langword="false"/>, always uses the name of the member, the same as if <c>ToString()</c> was called.</param>
5050
/// <returns>The string representation of the value</returns>
5151
public static string ToStringFast(this global::MyEnum value, bool useMetadataAttributes)
52-
=> useMetadataAttributes ? value.ToStringFastWithMetadata() : value.ToStringFast();
53-
54-
private static string ToStringFastWithMetadata(this global::MyEnum value)
5552
=> value.ToStringFast();
5653

5754
/// <summary>

tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsInNestedClass.verified.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//------------------------------------------------------------------------------
1+
//------------------------------------------------------------------------------
22
// <auto-generated>
33
// This code was generated by the NetEscapades.EnumGenerators source generator
44
//
@@ -51,9 +51,6 @@ namespace MyTestNameSpace
5151
/// If <see langword="false"/>, always uses the name of the member, the same as if <c>ToString()</c> was called.</param>
5252
/// <returns>The string representation of the value</returns>
5353
public static string ToStringFast(this global::MyTestNameSpace.InnerClass.MyEnum value, bool useMetadataAttributes)
54-
=> useMetadataAttributes ? value.ToStringFastWithMetadata() : value.ToStringFast();
55-
56-
private static string ToStringFastWithMetadata(this global::MyTestNameSpace.InnerClass.MyEnum value)
5754
=> value.ToStringFast();
5855

5956
/// <summary>

tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsWithCustomName.verified.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//------------------------------------------------------------------------------
1+
//------------------------------------------------------------------------------
22
// <auto-generated>
33
// This code was generated by the NetEscapades.EnumGenerators source generator
44
//
@@ -51,9 +51,6 @@ namespace MyTestNameSpace
5151
/// If <see langword="false"/>, always uses the name of the member, the same as if <c>ToString()</c> was called.</param>
5252
/// <returns>The string representation of the value</returns>
5353
public static string ToStringFast(this global::MyTestNameSpace.MyEnum value, bool useMetadataAttributes)
54-
=> useMetadataAttributes ? value.ToStringFastWithMetadata() : value.ToStringFast();
55-
56-
private static string ToStringFastWithMetadata(this global::MyTestNameSpace.MyEnum value)
5754
=> value.ToStringFast();
5855

5956
/// <summary>

tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsWithCustomNamespace.verified.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//------------------------------------------------------------------------------
1+
//------------------------------------------------------------------------------
22
// <auto-generated>
33
// This code was generated by the NetEscapades.EnumGenerators source generator
44
//
@@ -51,9 +51,6 @@ namespace A.B
5151
/// If <see langword="false"/>, always uses the name of the member, the same as if <c>ToString()</c> was called.</param>
5252
/// <returns>The string representation of the value</returns>
5353
public static string ToStringFast(this global::MyTestNameSpace.MyEnum value, bool useMetadataAttributes)
54-
=> useMetadataAttributes ? value.ToStringFastWithMetadata() : value.ToStringFast();
55-
56-
private static string ToStringFastWithMetadata(this global::MyTestNameSpace.MyEnum value)
5754
=> value.ToStringFast();
5855

5956
/// <summary>

tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsWithCustomNamespaceAndName.verified.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//------------------------------------------------------------------------------
1+
//------------------------------------------------------------------------------
22
// <auto-generated>
33
// This code was generated by the NetEscapades.EnumGenerators source generator
44
//
@@ -51,9 +51,6 @@ namespace A.B
5151
/// If <see langword="false"/>, always uses the name of the member, the same as if <c>ToString()</c> was called.</param>
5252
/// <returns>The string representation of the value</returns>
5353
public static string ToStringFast(this global::MyTestNameSpace.MyEnum value, bool useMetadataAttributes)
54-
=> useMetadataAttributes ? value.ToStringFastWithMetadata() : value.ToStringFast();
55-
56-
private static string ToStringFastWithMetadata(this global::MyTestNameSpace.MyEnum value)
5754
=> value.ToStringFast();
5855

5956
/// <summary>

tests/NetEscapades.EnumGenerators.Tests/Snapshots/EnumGeneratorTests.CanGenerateEnumExtensionsWithWrongMetadataName__.verified.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//------------------------------------------------------------------------------
1+
//------------------------------------------------------------------------------
22
// <auto-generated>
33
// This code was generated by the NetEscapades.EnumGenerators source generator
44
//
@@ -53,9 +53,6 @@ namespace MyTestNameSpace
5353
/// If <see langword="false"/>, always uses the name of the member, the same as if <c>ToString()</c> was called.</param>
5454
/// <returns>The string representation of the value</returns>
5555
public static string ToStringFast(this global::MyTestNameSpace.MyEnum value, bool useMetadataAttributes)
56-
=> useMetadataAttributes ? value.ToStringFastWithMetadata() : value.ToStringFast();
57-
58-
private static string ToStringFastWithMetadata(this global::MyTestNameSpace.MyEnum value)
5956
=> value.ToStringFast();
6057

6158
/// <summary>

0 commit comments

Comments
 (0)