Monkeymoto.GeneratorUtils.GenericSymbolReferenceTree 2.0.0.1

dotnet add package Monkeymoto.GeneratorUtils.GenericSymbolReferenceTree --version 2.0.0.1
NuGet\Install-Package Monkeymoto.GeneratorUtils.GenericSymbolReferenceTree -Version 2.0.0.1
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="Monkeymoto.GeneratorUtils.GenericSymbolReferenceTree" Version="2.0.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Monkeymoto.GeneratorUtils.GenericSymbolReferenceTree --version 2.0.0.1
#r "nuget: Monkeymoto.GeneratorUtils.GenericSymbolReferenceTree, 2.0.0.1"
#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 Monkeymoto.GeneratorUtils.GenericSymbolReferenceTree as a Cake Addin
#addin nuget:?package=Monkeymoto.GeneratorUtils.GenericSymbolReferenceTree&version=2.0.0.1

// Install Monkeymoto.GeneratorUtils.GenericSymbolReferenceTree as a Cake Tool
#tool nuget:?package=Monkeymoto.GeneratorUtils.GenericSymbolReferenceTree&version=2.0.0.1

GenericSymbolReferenceTree

C# incremental generator utility to produce a tree of closed generic symbols used in your project's compilation, each paired with a syntax node.

How to use this project

This project is designed to be used with a C# incremental generator to discover closed generic symbols that are referenced in your project's compilation. Accordingly, the first step in using this project is to add the necessary references to your csproj file.

The pre-built binaries of this project are available as a NuGet Package. Your csproj file may look like this:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Library</OutputType>
    <TargetFramework>netstandard2.0</TargetFramework>
    <Nullable>enable</Nullable>
    <LangVersion>preview</LangVersion>
    <EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
    <PublishAot>false</PublishAot>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.8.0" PrivateAssets="all" />
    <PackageReference Include="Monkeymoto.GeneratorUtils.GenericSymbolReferenceTree" Version="2.0.0">
      <PrivateAssets>all</PrivateAssets>
      <GeneratePathProperty>true</GeneratePathProperty>
    </PackageReference>
  </ItemGroup>

  <PropertyGroup>
    <GetTargetPathDependsOn>$(GetTargetPathDependsOn);GetDependencyTargetPaths</GetTargetPathDependsOn>
  </PropertyGroup>

  <Target Name="GetDependencyTargetPaths">
    <ItemGroup>
      <TargetPathWithTargetPlatformMoniker Include="$(PKGMonkeymoto_GeneratorUtils_GenericSymbolReferenceTree)\lib\netstandard2.0\Monkeymoto.GeneratorUtils.GenericSymbolReferenceTree.dll" IncludeRuntimeDependency="false" />
    </ItemGroup>
  </Target>

</Project>

Once this project has been added to your incremental generator, you can then use the GenericSymbolReferenceTree.FromIncrementalGeneratorInitializationContext method to get an IncrementalValueProvider which gives you access to the tree. For example:

using Microsoft.CodeAnalysis;

namespace MyProjectGenerator
{
    [Generator]
    internal class MyGenerator : IIncrementalGenerator
    {
        public void Initialize(IncrementalGeneratorInitializationContext context)
        {
            var symbolTree = Monkeymoto.GeneratorUtils.GenericSymbolReferenceTree.FromIncrementalGeneratorInitializationContext(context);
            var symbolToFind = context.CompilationProvider.Select(static (compilation, _) =>
            {
                return compilation.GetTypeByMetadataName("MyProject.MyGenericType`1")!;
            });
            var symbols = symbolTree.Combine(symbolToFind).Select(static (x, cancellationToken) =>
            {
                var (symbolTree, symbolToFind) = x;
                return symbolTree.GetBranchesBySymbol(symbolToFind, cancellationToken);
            });
            // `symbols` is an `IncrementalValueProvider<IEnumerable<GenericSymbolReference>>`
            // this represents each *closed* instance of `MyProject.MyGenericType<T>` in the compilation
            // i.e., `MyProject.MyGenericType<int>`, `MyProject.MyGenericType<double>`, etc.
        }
    }
}

The methods GetBranch and GetBranchesBySymbol are provided by the GenericSymbolReferenceTree, and can be used to retrieve the closed generic symbols used in your project's compilation, each paired with the relevant syntax nodes.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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 was computed.  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.
  • .NETStandard 2.0

    • No dependencies.

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
2.0.0.1 110 2/16/2024