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
Theeasiestwaytoaddthepolyfillistousethe [Polyfill](https://github.com/SimonCropp/Polyfill) NuGet package, which provides this and many other missing types for older frameworks.
Theeasiestwaytoaddthepolyfillistousethe [Polyfill](https://github.com/SimonCropp/Polyfill) NuGet package, which provides this and many other missing types for older frameworks.
Copy file name to clipboardExpand all lines: docs/README.md
+15-24Lines changed: 15 additions & 24 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
<!--
2
2
GENERATED FILE - DO NOT EDIT
3
3
This file was generated by [MarkdownSnippets](https://github.com/SimonCropp/MarkdownSnippets).
4
-
Source File: /docs/README.source.md
4
+
Source File: /README.source.md
5
5
To change this file edit the source file and then run MarkdownSnippets.
6
6
-->
7
7
@@ -37,7 +37,7 @@ To change this file edit the source file and then run MarkdownSnippets.
37
37
38
38
## Why use these packages?
39
39
40
-
Many methods that work with enums are surprisingly slow. Calling `ToString()` or `HasFlag()` on an enum seems like it _should_ be fast, but it often isn't. This package provides a set of extension methods, such as `ToStringFast()` or `HasFlagFast()` that are designed to be very fast, with fewer allocations.<!-- include: benchmark. path: /docs/fragments/benchmark.include.md -->
40
+
Many methods that work with enums are surprisingly slow. Calling `ToString()` or `HasFlag()` on an enum seems like it _should_ be fast, but it often isn't. This package provides a set of extension methods, such as `ToStringFast()` or `HasFlagFast()` that are designed to be very fast, with fewer allocations.<!-- include: benchmark. path: /fragments/benchmark.include.md -->
41
41
42
42
43
43
For example, the following benchmark shows the advantage of calling `ToStringFast()` over `ToString()`:
@@ -100,7 +100,7 @@ This adds a `<PackageReference>` to your project:
100
100
> [!WARNING]
101
101
> You should _not_ use `PrivateAssets` when referencing the [NetEscapades.EnumGenerators](https://www.nuget.org/packages/NetEscapades.EnumGenerators) package, as the package has runtime dependencies. If you wish to avoid these runtime dependencies, [see below](#package-referencing-options) for alternative approaches.
102
102
103
-
Adding the package will automatically add a marker attribute, `[EnumExtensions]`, to your project.<!-- include: enum-usage. path: /docs/fragments/enum-usage.include.md -->
103
+
Adding the package will automatically add a marker attribute, `[EnumExtensions]`, to your project.<!-- include: enum-usage. path: /fragments/enum-usage.include.md -->
104
104
105
105
To use the generator, add the `[EnumExtensions]` attribute to an enum. For example:
_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()`.
@@ -419,7 +419,7 @@ All usage analyzers include automatic code fixes. When a diagnostic is triggered
419
419
420
420
<!-- endInclude -->
[NetEscapades.EnumGenerators](https://www.nuget.org/packages/NetEscapades.EnumGenerators) is a metapackage that references additional packages for functionality.
@@ -554,7 +554,7 @@ The final option is to reference [NetEscapades.EnumGenerators.Generators](https:
554
554
555
555
## Enabling automatic interception (experimental)
556
556
557
-
Themaindownsidetotheextensionmethodsgeneratedby [NetEscapades.EnumGenerators](https://www.nuget.org/packages/NetEscapades.EnumGenerators) is that you have to remember to use them. The [NetEscapades.EnumGenerators.Interceptors](https://www.nuget.org/packages/NetEscapades.EnumGenerators.Interceptors) package solves this problem by intercepting calls to `ToString()` and replacing them with calls `ToStringFast()` automatically using the .NET compiler feature called [interceptors](https://github.com/dotnet/roslyn/blob/main/docs/features/interceptors.md).<!-- include: interceptor-intro. path: /docs/fragments/interceptor-intro.include.md -->
557
+
Themaindownsidetotheextensionmethodsgeneratedby [NetEscapades.EnumGenerators](https://www.nuget.org/packages/NetEscapades.EnumGenerators) is that you have to remember to use them. The [NetEscapades.EnumGenerators.Interceptors](https://www.nuget.org/packages/NetEscapades.EnumGenerators.Interceptors) package solves this problem by intercepting calls to `ToString()` and replacing them with calls `ToStringFast()` automatically using the .NET compiler feature called [interceptors](https://github.com/dotnet/roslyn/blob/main/docs/features/interceptors.md).<!-- include: interceptor-intro. path: /fragments/interceptor-intro.include.md -->
Thisaddsa `<PackageReference>` toyourproject. Youcanadditionallymarkthepackageas `PrivateAssets="all"` and `ExcludeAssets="runtime"`, similarlyto_NetEscapades.EnumGenerators_.
587
587
588
-
Bydefault, adding [NetEscapades.EnumGenerators.Interceptors](https://www.nuget.org/packages/NetEscapades.EnumGenerators.Interceptors) to a project enables interception for all enums _defined in that project_ that use the `[EnumExtensions]` or `[EnumExtensions<T>]` attributes. If you wish to intercept calls made to enums with extensions defined in _other_ projects, you must add the `[Interceptable<T>]` attribute in the project where you want the interception to happen, e.g.<!-- include: interception-config. path: /docs/fragments/interception-config.include.md -->
588
+
Bydefault, adding [NetEscapades.EnumGenerators.Interceptors](https://www.nuget.org/packages/NetEscapades.EnumGenerators.Interceptors) to a project enables interception for all enums _defined in that project_ that use the `[EnumExtensions]` or `[EnumExtensions<T>]` attributes. If you wish to intercept calls made to enums with extensions defined in _other_ projects, you must add the `[Interceptable<T>]` attribute in the project where you want the interception to happen, e.g.<!-- include: interception-config. path: /fragments/interception-config.include.md -->
Theeasiestwaytoaddthepolyfillistousethe [Polyfill](https://github.com/SimonCropp/Polyfill) NuGet package, which provides this and many other missing types for older frameworks.
## Preserving usages of the `[EnumExtensions]` attribute
697
688
698
689
The `[EnumExtensions]` attributeisdecoratedwiththe `[Conditional]` attribute, [sotheirusagewillnotappearinthebuildoutputofyourproject](https://andrewlock.net/conditional-compilation-for-ignoring-method-calls-with-the-conditionalattribute/#applying-the-conditional-attribute-to-classes). If you use reflection at runtime on one of your `enum`s, you will not find `[EnumExtensions]` in the list of custom attributes. If you wish to preserve these attributes in the build output, you can define the `NETESCAPADES_ENUMGENERATORS_USAGES` MSBuild variable.
0 commit comments