NetFabric.CodeAnalysis 5.0.0

Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
dotnet add package NetFabric.CodeAnalysis --version 5.0.0                
NuGet\Install-Package NetFabric.CodeAnalysis -Version 5.0.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="NetFabric.CodeAnalysis" Version="5.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add NetFabric.CodeAnalysis --version 5.0.0                
#r "nuget: NetFabric.CodeAnalysis, 5.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install NetFabric.CodeAnalysis as a Cake Addin
#addin nuget:?package=NetFabric.CodeAnalysis&version=5.0.0

// Install NetFabric.CodeAnalysis as a Cake Tool
#tool nuget:?package=NetFabric.CodeAnalysis&version=5.0.0                

NetFabric.CodeAnalysis

This package extends the API provided by Roslyn. It can be used in the development of Roslyn Analyzers and Source Generators.

Enumerable type checking

To find if a type is enumerable, it's not enough to check if it implements IEnumerable, IEnumerable<> or IAsyncEnumerable<>. The foreach and await foreach statements support several other cases.

NOTE: Check the article "Efficient Data Processing: Leveraging C#'s foreach Loop" to understand all the possible cases supported by the foreach statement.

This package provides extension methods for the interface ITypeSymbol that can correctly validate if the type it represents can be used as the source in foreach or await foreach statements.

IsEnumerable

public static bool IsEnumerable(this ITypeSymbol typeSymbol,
    Compilation compilation,
    [NotNullWhen(true)] out EnumerableSymbols? enumerableSymbols,
    out IsEnumerableError error);

The method returns true if the type represented by ITypeSymbol can be used in a foreach statement; otherwise false. It supports all the cases including when GetEnumerator() is defined as an extension method.

If it returns true, the enumerableSymbols output parameter contains all the IMethodInfo and IPropertySymbol for the methods and properties that are going to be actually used by the foreach statement. The GetEnumerator() of the enumerable, the property Current and the method MoveNext() of the enumerator. It may also contain info for methods Reset() and Dispose() of the enumerator, if defined.

If it returns false, the error output parameter indicates why the type is not considered an enumerable. It can be MissingGetEnumerator, MissingCurrent or MissingMoveNext.

The output parameter also includes a ForEachUsesIndexer boolean property that indicates that, although the collection provides an enumerator, foreach will use the indexer instead. That's the case for arrays and spans.

You can use these info values to further validate the enumerable and its respective enumerator. For example, use the following to find if the Current property of the enumerator returns by reference:

enumerableSymbols.EnumeratorSymbols.Current.ReturnsByRef;

IsAsyncEnumerable

public static bool IsAsyncEnumerable(this ITypeSymbol typeSymbol,
    Compilation compilation,
    [NotNullWhen(true)] out AsyncEnumerableSymbols? enumerableSymbols,
    out IsAsyncEnumerableError error);

The method returns true if the type represented by ITypeSymbol can be used in an await foreach statement; otherwise false. It supports all the cases including when GetAsyncEnumerator() is defined as an extension method.

If it returns true, the enumerableSymbols output parameter contains all the IMethodInfo and IPropertySymbol for the methods and properties that are going to be actually used by the await foreach statement. The GetAsyncEnumerator() of the enumerable, the property Current and the method MoveNextAsync() of the enumerator. It may also contain info for method DisposeAsync() of the enumerator, if defined.

If it returns false, the error output parameter indicates why the type is not considered an enumerable. It can be MissingGetAsyncEnumerator, MissingCurrent or MissingMoveNextAsync.

You can use these info values to further validate the async enumerable or its respective enumerator.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 is compatible.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
5.1.0 280 10/11/2023
5.0.0 136 10/10/2023
4.2.2 215 9/16/2023
4.2.1 121 9/16/2023
4.2.0 160 9/7/2023
4.1.0 231 7/14/2023
4.0.2 39,206 7/10/2021
4.0.1 1,229 4/15/2021
4.0.0 369 4/14/2021 4.0.0 is deprecated because it has critical bugs.
3.1.1 330 3/31/2021
3.1.0 321 3/26/2021
3.0.0 3,591 5/1/2020
2.0.1 481 4/29/2020
2.0.0 1,947 12/11/2019
1.1.0 464 12/7/2019
1.0.0 452 12/5/2019

Removed IsEnumerator() and IsAsyncEnumerator.
   Error enums defined discrete values, not flags.
   Added IsIndexable().
   Fixed miscelaneous bugs.