Home

Awesome

GitHub last commit (master) Build (master) Coverage NuGet Version NuGet Downloads Gitter

NetFabric.Hyperlinq.Analyzer

A Roslyn Analyzer that contains several rules to help improve enumeration performance when using C#.

Note: This analyzer is independent of NetFabric.Hyperlinq. The rules may be useful when you only use foreach, IEnumerable<T>, IAsyncEnumerable<T>, System.Linq or System.Linq.Async.

Rule IDCategorySeverityNotes
HLQ001PerformanceWarningAssigment to interface causes boxing of enumerator
HLQ002CompilerErrorEnumerable cannot be null.
HLQ003PerformanceWarningPublic methods should return highest admissible level interface.
HLQ004PerformanceWarningThe enumerator returns a reference to the item.
HLQ005PerformanceWarningAvoid use of Single() and SingleOrDefault()
HLQ006PerformanceWarningGetEnumerator() or GetAsyncEnumerator() should return a value type.
HLQ007PerformanceWarningConsider returning a non-disposable enumerator.
HLQ008PerformanceInfoThe enumerable is a value type. Consider making it readonly.
HLQ009PerformanceInfoConsider removing an empty optional enumerator method.
HLQ011CompilerErrorMutable value-type enumerators cannot be stored in a readonly field.
HLQ012PerformanceWarningConsider using CollectionsMarshal.AsSpan() when iterating a List<T>.
HLQ013PerformanceWarningConsider using foreach when iterating an array or a Span<T>.

Usage

Visual Studio Marketplace

Install the NetFabric.Hyperlinq.Analyzer extension from the Visual Studio Marketplace.

Nuget package

Add the NetFabric.Hyperlinq.Analyzer package to your project using your favorite NuGet client.

If added manually to the .csproj, make sure to set PrivateAssets to all so that it's not added as a dependency. A floating version can be used to get the latest version.

<PackageReference Include="NetFabric.Hyperlinq.Analyzer" Version="2.*">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>

References

Credits

The following open-source projects are used to build and test this project: