File tree 3 files changed +11
-9
lines changed
src/EnumFastToStringDotNet
3 files changed +11
-9
lines changed Original file line number Diff line number Diff line change @@ -18,17 +18,17 @@ Benchmark done with [BenchmarkDotNet](https://benchmarkdotnet.org/). You can run
18
18
## Quick Start
19
19
20
20
1 . Add source generator reference to your project
21
- ```
21
+ ``` xml
22
22
<ItemGroup >
23
23
<ProjectReference Include =" path\to\EnumFastToStringDotNet.csproj" OutputItemType =" Analyzer" ReferenceOutputAssembly =" false" />
24
24
</ItemGroup >
25
25
```
26
26
2 . Add using statement
27
- ```
27
+ ``` c#
28
28
using EnumFastToStringGenerated ;
29
29
```
30
30
3 . Add [ FastToString] attribute to your enum
31
- ```
31
+ ``` c#
32
32
[FastToString ]
33
33
public enum HumanStates
34
34
{
@@ -40,12 +40,12 @@ public enum HumanStates
40
40
}
41
41
```
42
42
4 . Call FastToString method
43
- ```
43
+ ``` c#
44
44
Console .Out .WriteLine (HumanStates .Dead .FastToString ());
45
45
```
46
46
47
47
5 . The Automatically Generated Code
48
- ```
48
+ ``` c#
49
49
using System ;
50
50
namespace EnumFastToStringGenerated
51
51
{
@@ -70,7 +70,7 @@ namespace EnumFastToStringGenerated
70
70
## Custom Method Name
71
71
72
72
If you would like to use a different method name, you can do so with the attribute argument "MethodName".
73
- ```
73
+ ``` c#
74
74
[FastToString (MethodName = " CustomMethodName" )]
75
75
public enum HumanStates
76
76
{
@@ -82,14 +82,14 @@ public enum HumanStates
82
82
}
83
83
```
84
84
Then you can call the method like this:
85
- ```
85
+ ``` c#
86
86
Console .Out .WriteLine (HumanStates .Dead .CustomMethodName ());
87
87
```
88
88
89
89
## Customizing Source Generator
90
90
91
91
You can customize the source generator by changing the const values in the EnumSwitchSourceGenerator.cs file.
92
- ```
92
+ ``` c#
93
93
// The namespace that the attribute and extension method classes are defined in
94
94
private const string NAMESPACE = " EnumFastToStringGenerated" ;
95
95
Original file line number Diff line number Diff line change 1
1
using System ;
2
+ using System . ComponentModel ;
2
3
using BenchmarkDotNet . Attributes ;
3
4
using BenchmarkDotNet . Running ;
4
5
using EnumFastToStringGenerated ;
@@ -78,6 +79,7 @@ public string SwitchExpressionToString(HumanStates state)
78
79
[ FastToString ]
79
80
public enum HumanStates
80
81
{
82
+ [ Description ( "Not doing anything" ) ]
81
83
Idle ,
82
84
Working ,
83
85
Sleeping ,
Original file line number Diff line number Diff line change @@ -58,7 +58,7 @@ public static class EnumExtensions
58
58
return states switch
59
59
{{
60
60
" ) ;
61
- foreach ( string member in e . Members . Select ( x => x . ToString ( ) ) )
61
+ foreach ( string member in e . Members . Select ( x => x . Identifier . ValueText ) )
62
62
sourceBuilder . AppendLine ( $@ " { symbolName } .{ member } => nameof({ symbolName } .{ member } ),") ;
63
63
sourceBuilder . Append ( @" _ => throw new ArgumentOutOfRangeException(nameof(states), states, null)
64
64
};
You can’t perform that action at this time.
0 commit comments