Skip to content

A Roslyn analyzer with rules related to generation and consumption of enumerables and async enumerables in C#.

License

Notifications You must be signed in to change notification settings

DavidTCarpenters/NetFabric.Hyperlinq.Analyzer

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 ID Category Severity Notes
HLQ001 Performance Warning Assigment to interface causes boxing of enumerator
HLQ002 Compiler Error Enumerable cannot be null.
HLQ003 Performance Warning Public methods should return highest admissible level interface.
HLQ004 Performance Warning The enumerator returns a reference to the item.
HLQ005 Performance Warning Avoid use of Single() and SingleOrDefault()
HLQ006 Performance Warning GetEnumerator() or GetAsyncEnumerator() should return a value type.
HLQ007 Performance Warning Consider returning a non-disposable enumerator.
HLQ008 Performance Info The enumerable is a value type. Consider making it readonly.
HLQ009 Performance Info Consider removing an empty optional enumerator method.
HLQ011 Compiler Error Mutable value-type enumerators cannot be stored in a readonly field.
HLQ012 Performance Warning Consider using CollectionsMarshal.AsSpan() when iterating a List<T>.
HLQ013 Performance Warning Consider 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:

About

A Roslyn analyzer with rules related to generation and consumption of enumerables and async enumerables in C#.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 89.2%
  • PowerShell 10.8%