Skip to content

TypeDiscoveryHelper

NexusLabs.Needlr.Generators

NexusLabs.Needlr.Roslyn.Shared

TypeDiscoveryHelper Class

Shared helper utilities for discovering injectable types from Roslyn symbols. Used by both Generators and Analyzers to ensure consistent type discovery logic.

public static class TypeDiscoveryHelper

Inheritance System.Object 🡒 TypeDiscoveryHelper

Methods

TypeDiscoveryHelper.HasDoNotAutoRegisterAttribute(INamedTypeSymbol) Method

Checks if a type has the [DoNotAutoRegister] attribute (directly or on interfaces).

public static bool HasDoNotAutoRegisterAttribute(INamedTypeSymbol typeSymbol);

Parameters

typeSymbol Microsoft.CodeAnalysis.INamedTypeSymbol

Returns

System.Boolean

TypeDiscoveryHelper.HasDoNotAutoRegisterAttributeDirect(INamedTypeSymbol) Method

Checks if a type has the [DoNotAutoRegister] or [DoNotInject] attribute directly applied.

public static bool HasDoNotAutoRegisterAttributeDirect(INamedTypeSymbol typeSymbol);

Parameters

typeSymbol Microsoft.CodeAnalysis.INamedTypeSymbol

Returns

System.Boolean

TypeDiscoveryHelper.HasUnsatisfiedRequiredMembers(INamedTypeSymbol) Method

Checks if a type has required members that aren't satisfied by any constructor with [SetsRequiredMembers] attribute.

public static bool HasUnsatisfiedRequiredMembers(INamedTypeSymbol typeSymbol);

Parameters

typeSymbol Microsoft.CodeAnalysis.INamedTypeSymbol

Returns

System.Boolean

TypeDiscoveryHelper.InheritsFrom(INamedTypeSymbol, string) Method

Checks if a type inherits from a base type by name.

public static bool InheritsFrom(INamedTypeSymbol typeSymbol, string baseTypeName);

Parameters

typeSymbol Microsoft.CodeAnalysis.INamedTypeSymbol

baseTypeName System.String

Returns

System.Boolean

TypeDiscoveryHelper.IsAccessibleFromGeneratedCode(INamedTypeSymbol, bool) Method

Checks if a type is accessible from generated code. For types in the current assembly, internal and public types are accessible. For types in referenced assemblies, only public types are accessible.

public static bool IsAccessibleFromGeneratedCode(INamedTypeSymbol typeSymbol, bool isCurrentAssembly);

Parameters

typeSymbol Microsoft.CodeAnalysis.INamedTypeSymbol

isCurrentAssembly System.Boolean

Returns

System.Boolean

TypeDiscoveryHelper.IsCompilerGenerated(INamedTypeSymbol) Method

Checks if a type is compiler-generated.

public static bool IsCompilerGenerated(INamedTypeSymbol typeSymbol);

Parameters

typeSymbol Microsoft.CodeAnalysis.INamedTypeSymbol

Returns

System.Boolean

TypeDiscoveryHelper.IsInjectableType(INamedTypeSymbol, bool) Method

Determines whether a type symbol represents a concrete injectable type.

public static bool IsInjectableType(INamedTypeSymbol typeSymbol, bool isCurrentAssembly=false);

Parameters

typeSymbol Microsoft.CodeAnalysis.INamedTypeSymbol

The type symbol to check.

isCurrentAssembly System.Boolean

True if the type is from the current compilation's assembly (allows internal types).

Returns

System.Boolean
True if the type is a valid injectable type; otherwise, false.

TypeDiscoveryHelper.IsSystemType(INamedTypeSymbol) Method

Checks if a type is from the System namespace or system assemblies.

public static bool IsSystemType(INamedTypeSymbol typeSymbol);

Parameters

typeSymbol Microsoft.CodeAnalysis.INamedTypeSymbol

Returns

System.Boolean