You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+52Lines changed: 52 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -340,6 +340,58 @@ Interception only works when the target type is unambiguously an interceptable e
340
340
- If the `ToString()` call is made on a base type, such as `System.Enum` or `object`
341
341
- If the `ToString()` call is made on a generic type
342
342
343
+
## Usage Analyzers
344
+
345
+
_NetEscapades.EnumGenerators_ includes optional analyzers that encourage the use of the generated extension methods instead of the built-in `System.Enum` methods. These analyzers can help improve performance by suggesting the faster, generated, alternatives like `ToStringFast()`, `HasFlagFast()`, and `TryParse()`.
346
+
347
+
### Enabling the analyzers
348
+
349
+
The usage analyzers are disabled by default. To enable them, add a `.globalconfig` file to your project with the following content:
The project should auto detect the analyzers, and enables all of the usage analyzers with the default severity.
357
+
### Configuring analyzer severity (optional)
358
+
359
+
Once enabled, you can optionally configure the severity of individual analyzer rules using an `.editorconfig` file. For example:
360
+
361
+
```ini
362
+
[*.{cs,vb}]
363
+
364
+
# NEEG004: Use ToStringFast() instead of ToString()
365
+
dotnet_diagnostic.NEEG004.severity = warning
366
+
367
+
# NEEG005: Use HasFlagFast() instead of HasFlag()
368
+
dotnet_diagnostic.NEEG005.severity = warning
369
+
370
+
# NEEG006: Use generated IsDefined() instead of Enum.IsDefined()
371
+
dotnet_diagnostic.NEEG006.severity = warning
372
+
373
+
# NEEG007: Use generated Parse() instead of Enum.Parse()
374
+
dotnet_diagnostic.NEEG007.severity = warning
375
+
376
+
# NEEG008: Use generated GetNames() instead of Enum.GetNames()
377
+
dotnet_diagnostic.NEEG008.severity = warning
378
+
379
+
# NEEG009: Use generated GetValues() instead of Enum.GetValues()
380
+
dotnet_diagnostic.NEEG009.severity = warning
381
+
382
+
# NEEG010: Use generated GetValuesAsUnderlyingType() instead of Enum.GetValuesAsUnderlyingType()
383
+
dotnet_diagnostic.NEEG010.severity = warning
384
+
385
+
# NEEG011: Use generated TryParse() instead of Enum.TryParse()
386
+
dotnet_diagnostic.NEEG011.severity = warning
387
+
```
388
+
389
+
Valid severity values include: `none`, `silent`, `suggestion`, `warning`, and `error`.
390
+
391
+
### Code fixes
392
+
393
+
All usage analyzers include automatic code fixes. When a diagnostic is triggered, you can use the quick fix functionality in your IDE to automatically replace the `System.Enum` method with the corresponding generated extension method.
394
+
343
395
## Embedding the attributes in your project
344
396
345
397
By default, the `[EnumExtensions]` attributes referenced in your application are contained in an external dll. It is also possible to embed the attributes directly in your project, so they appear in the dll when your project is built. If you wish to do this, you must do two things:
0 commit comments