TypeSymbolExtensions Class

internal static class TypeSymbolExtensions

No documentation is available.

Methods

NameDescription
GetAllInterfacesIncludingSelf(ITypeSymbol)
GetAllMembers(ITypeSymbol?, bool)Enumerates the members of symbol and of its base types.
GetAllMembers(ITypeSymbol?, string, bool)Enumerates the members named name of symbol and of its base types.
GetEnumUnderlyingType(ITypeSymbol?)
GetUnderlyingNullableTypeOrSelf(ITypeSymbol?)
Implements(ITypeSymbol, ITypeSymbol?)Determines whether classSymbol implements interfaceType. An interface is not considered to implement itself.
ImplementsGenericInterface(ITypeSymbol, ITypeSymbol?)Determines whether classSymbol implements a construction of the generic interface interfaceType, whatever its type arguments are. An interface is not considered to implement itself.
InheritsFrom(ITypeSymbol, ITypeSymbol?)Determines whether classSymbol derives from baseClassType. A type is not considered to derive from itself.
IsAssignableFrom(ITypeSymbol, ITypeSymbol?)Determines whether a value of type sourceType can be assigned to a variable of type type while keeping its identity.
IsAssignableTo(ITypeSymbol, ITypeSymbol?)Determines whether a value of type type can be assigned to a variable of type targetType while keeping its identity, that is through an identity, an implicit reference or a boxing conversion.
IsBlittableType(ITypeSymbol?)Determines whether the type is a blittable type. Blittable types: byte, sbyte, short, ushort, int, uint, long, ulong, float, double, IntPtr, UIntPtr, pointers, enums, and structs containing only blittable fields.
IsBoolean(ITypeSymbol?)
IsChar(ITypeSymbol?)
IsDateTime(ITypeSymbol?)
IsEnum(ITypeSymbol?)
IsEqualToAny(ITypeSymbol?, ITypeSymbol?)
IsEqualToAny(ITypeSymbol?, ITypeSymbol?, ITypeSymbol?)
IsEqualToAny(ITypeSymbol?, ITypeSymbol?, ITypeSymbol?, ITypeSymbol?)
IsEqualToAny(ITypeSymbol?, ReadOnlySpan<ITypeSymbol?>)
IsInt32(ITypeSymbol?)
IsNumberType(ITypeSymbol?)
IsObject(ITypeSymbol?)
IsOrImplements(ITypeSymbol, ITypeSymbol?)Determines whether symbol is interfaceType or implements it.
IsOrInheritsFrom(ITypeSymbol, ITypeSymbol?)Determines whether symbol is expectedType or derives from it.
IsString(ITypeSymbol?)

GetAllInterfacesIncludingSelf(ITypeSymbol)

public static ImmutableArray<INamedTypeSymbol> GetAllInterfacesIncludingSelf(this ITypeSymbol type)

No documentation is available.

GetAllMembers overloads

GetAllMembers(ITypeSymbol?, bool)

Enumerates the members of symbol and of its base types.

public static IEnumerable<ISymbol> GetAllMembers(this ITypeSymbol? symbol, bool includeInterfaceMembers = false)
Parameters
symbol ITypeSymbol?
The type whose members are enumerated.
includeInterfaceMembers bool
true to also enumerate the members of all the interfaces implemented by symbol; otherwise, false. This parameter is ignored when symbol is an interface as the members of its base interfaces are always enumerated.
Returns

IEnumerable<ISymbol>

GetAllMembers(ITypeSymbol?, string, bool)

Enumerates the members named name of symbol and of its base types.

public static IEnumerable<ISymbol> GetAllMembers(this ITypeSymbol? symbol, string name, bool includeInterfaceMembers = false)
Parameters
symbol ITypeSymbol?
The type whose members are enumerated.
name string
The name of the members to enumerate.
includeInterfaceMembers bool
true to also enumerate the members of all the interfaces implemented by symbol; otherwise, false. This parameter is ignored when symbol is an interface as the members of its base interfaces are always enumerated.
Returns

IEnumerable<ISymbol>

GetEnumUnderlyingType(ITypeSymbol?)

public static INamedTypeSymbol? GetEnumUnderlyingType(this ITypeSymbol? symbol)

Parameters

symbol ITypeSymbol?

Returns

INamedTypeSymbol?

No documentation is available.

GetUnderlyingNullableTypeOrSelf(ITypeSymbol?)

public static ITypeSymbol? GetUnderlyingNullableTypeOrSelf(this ITypeSymbol? typeSymbol)

Parameters

typeSymbol ITypeSymbol?

Returns

ITypeSymbol?

No documentation is available.

Implements(ITypeSymbol, ITypeSymbol?)

Determines whether classSymbol implements interfaceType. An interface is not considered to implement itself.

public static bool Implements(this ITypeSymbol classSymbol, ITypeSymbol? interfaceType)

Parameters

classSymbol ITypeSymbol
interfaceType ITypeSymbol?

Returns

bool

Remarks

When classSymbol is a type parameter, its constraint types are inspected and a constraint that is interfaceType is a match, so T in where T : ISample implements ISample.

ImplementsGenericInterface(ITypeSymbol, ITypeSymbol?)

Determines whether classSymbol implements a construction of the generic interface interfaceType, whatever its type arguments are. An interface is not considered to implement itself.

public static bool ImplementsGenericInterface(this ITypeSymbol classSymbol, ITypeSymbol? interfaceType)

Parameters

classSymbol ITypeSymbol
interfaceType ITypeSymbol?

Returns

bool

Remarks

When classSymbol is a type parameter, its constraint types are inspected and a constraint that is a construction of interfaceType is a match, so T in where T : ISample<int> implements ISample<>.

InheritsFrom(ITypeSymbol, ITypeSymbol?)

Determines whether classSymbol derives from baseClassType. A type is not considered to derive from itself.

public static bool InheritsFrom(this ITypeSymbol classSymbol, ITypeSymbol? baseClassType)

Parameters

classSymbol ITypeSymbol
baseClassType ITypeSymbol?

Returns

bool

Remarks

When classSymbol is a type parameter, its constraint types are inspected and a constraint that is baseClassType is a match, so T in where T : Base derives from Base. TypeSymbolExtensions.Implements and TypeSymbolExtensions.ImplementsGenericInterface behave the same way.

IsAssignableFrom(ITypeSymbol, ITypeSymbol?)

Determines whether a value of type sourceType can be assigned to a variable of type type while keeping its identity.

public static bool IsAssignableFrom(this ITypeSymbol type, ITypeSymbol? sourceType)

Parameters

type ITypeSymbol
sourceType ITypeSymbol?

Returns

bool

Remarks

This is the reverse of TypeSymbolExtensions.IsAssignableTo, which documents the conversions taken into account.

IsAssignableTo(ITypeSymbol, ITypeSymbol?)

Determines whether a value of type type can be assigned to a variable of type targetType while keeping its identity, that is through an identity, an implicit reference or a boxing conversion.

public static bool IsAssignableTo(this ITypeSymbol type, ITypeSymbol? targetType)

Parameters

type ITypeSymbol
targetType ITypeSymbol?

Returns

bool

Remarks

This follows the C# conversion rules: a type is assignable to itself, to its base types, to the interfaces it implements, and to Object. The variance of generic interfaces and delegates, array covariance, and the constraints of type parameters are taken into account, so string[] is assignable to IEnumerable<object> and T in where T : IDisposable is assignable to IDisposable. object and dynamic are interchangeable, and so are tuples differing only by their element names.

Conversions that produce a different value are not considered: numeric, nullable, user-defined, tuple, pointer or span conversions. For instance, int is not assignable to long nor to int?, and IEnumerable<int> is not assignable to IEnumerable<object>.

IsBlittableType(ITypeSymbol?)

Determines whether the type is a blittable type. Blittable types: byte, sbyte, short, ushort, int, uint, long, ulong, float, double, IntPtr, UIntPtr, pointers, enums, and structs containing only blittable fields.

public static bool IsBlittableType(this ITypeSymbol? symbol)

Parameters

symbol ITypeSymbol?

Returns

bool

IsBoolean(ITypeSymbol?)

public static bool IsBoolean(this ITypeSymbol? symbol)

Parameters

symbol ITypeSymbol?

Returns

bool

No documentation is available.

IsChar(ITypeSymbol?)

public static bool IsChar(this ITypeSymbol? symbol)

Parameters

symbol ITypeSymbol?

Returns

bool

No documentation is available.

IsDateTime(ITypeSymbol?)

public static bool IsDateTime(this ITypeSymbol? symbol)

Parameters

symbol ITypeSymbol?

Returns

bool

No documentation is available.

IsEnum(ITypeSymbol?)

public static bool IsEnum(this ITypeSymbol? symbol)

Parameters

symbol ITypeSymbol?

Returns

bool

No documentation is available.

IsEqualToAny overloads

IsEqualToAny(ITypeSymbol?, ITypeSymbol?)

public static bool IsEqualToAny(this ITypeSymbol? symbol, ITypeSymbol? expectedType1)
Parameters
symbol ITypeSymbol?
expectedType1 ITypeSymbol?
Returns

bool

No documentation is available.

IsEqualToAny(ITypeSymbol?, ITypeSymbol?, ITypeSymbol?)

public static bool IsEqualToAny(this ITypeSymbol? symbol, ITypeSymbol? expectedType1, ITypeSymbol? expectedType2)
Parameters
symbol ITypeSymbol?
expectedType1 ITypeSymbol?
expectedType2 ITypeSymbol?
Returns

bool

No documentation is available.

IsEqualToAny(ITypeSymbol?, ITypeSymbol?, ITypeSymbol?, ITypeSymbol?)

public static bool IsEqualToAny(this ITypeSymbol? symbol, ITypeSymbol? expectedType1, ITypeSymbol? expectedType2, ITypeSymbol? expectedType3)
Parameters
symbol ITypeSymbol?
expectedType1 ITypeSymbol?
expectedType2 ITypeSymbol?
expectedType3 ITypeSymbol?
Returns

bool

No documentation is available.

IsEqualToAny(ITypeSymbol?, ReadOnlySpan<ITypeSymbol?>)

public static bool IsEqualToAny(this ITypeSymbol? symbol, params scoped ReadOnlySpan<ITypeSymbol?> expectedTypes)
Parameters
symbol ITypeSymbol?
expectedTypes ReadOnlySpan<ITypeSymbol?>
Returns

bool

No documentation is available.

IsInt32(ITypeSymbol?)

public static bool IsInt32(this ITypeSymbol? symbol)

Parameters

symbol ITypeSymbol?

Returns

bool

No documentation is available.

IsNumberType(ITypeSymbol?)

public static bool IsNumberType(this ITypeSymbol? symbol)

Parameters

symbol ITypeSymbol?

Returns

bool

No documentation is available.

IsObject(ITypeSymbol?)

public static bool IsObject(this ITypeSymbol? symbol)

Parameters

symbol ITypeSymbol?

Returns

bool

No documentation is available.

IsOrImplements(ITypeSymbol, ITypeSymbol?)

Determines whether symbol is interfaceType or implements it.

public static bool IsOrImplements(this ITypeSymbol symbol, ITypeSymbol? interfaceType)

Parameters

symbol ITypeSymbol
interfaceType ITypeSymbol?

Returns

bool

IsOrInheritsFrom(ITypeSymbol, ITypeSymbol?)

Determines whether symbol is expectedType or derives from it.

public static bool IsOrInheritsFrom(this ITypeSymbol symbol, ITypeSymbol? expectedType)

Parameters

symbol ITypeSymbol
expectedType ITypeSymbol?

Returns

bool

IsString(ITypeSymbol?)

public static bool IsString(this ITypeSymbol? symbol)

Parameters

symbol ITypeSymbol?

Returns

bool

No documentation is available.