Skip to content

Commit 07b3fac

Browse files
Copilotandrewlock
andauthored
Add Usage Analyzers documentation to README (#216)
* Initial plan * Add Usage Analyzers section to README Co-authored-by: andrewlock <18755388+andrewlock@users.noreply.github.com> * Apply suggestions from code review --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: andrewlock <18755388+andrewlock@users.noreply.github.com> Co-authored-by: Andrew Lock <andrewlock.net@gmail.com>
1 parent 51ffa89 commit 07b3fac

1 file changed

Lines changed: 52 additions & 0 deletions

File tree

README.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,58 @@ Interception only works when the target type is unambiguously an interceptable e
340340
- If the `ToString()` call is made on a base type, such as `System.Enum` or `object`
341341
- If the `ToString()` call is made on a generic type
342342

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:
350+
351+
```ini
352+
is_global = true
353+
netescapades.enumgenerators.usage_analyzers.enable = true
354+
```
355+
356+
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+
343395
## Embedding the attributes in your project
344396

345397
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

Comments
 (0)