TypeSymbolExtensions Class
internal static class TypeSymbolExtensionsNo documentation is available.
Methods
| Name | Description |
|---|---|
| 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
symbolITypeSymbol?- The type whose members are enumerated.
includeInterfaceMembersbooltrueto also enumerate the members of all the interfaces implemented bysymbol; otherwise,false. This parameter is ignored whensymbolis an interface as the members of its base interfaces are always enumerated.
Returns
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
symbolITypeSymbol?- The type whose members are enumerated.
namestring- The name of the members to enumerate.
includeInterfaceMembersbooltrueto also enumerate the members of all the interfaces implemented bysymbol; otherwise,false. This parameter is ignored whensymbolis an interface as the members of its base interfaces are always enumerated.
Returns
GetEnumUnderlyingType(ITypeSymbol?)
public static INamedTypeSymbol? GetEnumUnderlyingType(this ITypeSymbol? symbol)No documentation is available.
GetUnderlyingNullableTypeOrSelf(ITypeSymbol?)
public static ITypeSymbol? GetUnderlyingNullableTypeOrSelf(this ITypeSymbol? typeSymbol)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
classSymbolITypeSymbolinterfaceTypeITypeSymbol?
Returns
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
classSymbolITypeSymbolinterfaceTypeITypeSymbol?
Returns
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
classSymbolITypeSymbolbaseClassTypeITypeSymbol?
Returns
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
typeITypeSymbolsourceTypeITypeSymbol?
Returns
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
typeITypeSymboltargetTypeITypeSymbol?
Returns
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)IsBoolean(ITypeSymbol?)
public static bool IsBoolean(this ITypeSymbol? symbol)No documentation is available.
IsChar(ITypeSymbol?)
public static bool IsChar(this ITypeSymbol? symbol)No documentation is available.
IsDateTime(ITypeSymbol?)
public static bool IsDateTime(this ITypeSymbol? symbol)No documentation is available.
IsEnum(ITypeSymbol?)
public static bool IsEnum(this ITypeSymbol? symbol)No documentation is available.
IsEqualToAny overloads
IsEqualToAny(ITypeSymbol?, ITypeSymbol?)
public static bool IsEqualToAny(this ITypeSymbol? symbol, ITypeSymbol? expectedType1)No documentation is available.
IsEqualToAny(ITypeSymbol?, ITypeSymbol?, ITypeSymbol?)
public static bool IsEqualToAny(this ITypeSymbol? symbol, ITypeSymbol? expectedType1, ITypeSymbol? expectedType2)No documentation is available.
IsEqualToAny(ITypeSymbol?, ITypeSymbol?, ITypeSymbol?, ITypeSymbol?)
public static bool IsEqualToAny(this ITypeSymbol? symbol, ITypeSymbol? expectedType1, ITypeSymbol? expectedType2, ITypeSymbol? expectedType3)Parameters
symbolITypeSymbol?expectedType1ITypeSymbol?expectedType2ITypeSymbol?expectedType3ITypeSymbol?
Returns
No documentation is available.
IsEqualToAny(ITypeSymbol?, ReadOnlySpan<ITypeSymbol?>)
public static bool IsEqualToAny(this ITypeSymbol? symbol, params scoped ReadOnlySpan<ITypeSymbol?> expectedTypes)No documentation is available.
IsInt32(ITypeSymbol?)
public static bool IsInt32(this ITypeSymbol? symbol)No documentation is available.
IsNumberType(ITypeSymbol?)
public static bool IsNumberType(this ITypeSymbol? symbol)No documentation is available.
IsObject(ITypeSymbol?)
public static bool IsObject(this ITypeSymbol? symbol)No documentation is available.
IsOrImplements(ITypeSymbol, ITypeSymbol?)
Determines whether symbol is interfaceType or implements it.
public static bool IsOrImplements(this ITypeSymbol symbol, ITypeSymbol? interfaceType)IsOrInheritsFrom(ITypeSymbol, ITypeSymbol?)
Determines whether symbol is expectedType or derives from it.
public static bool IsOrInheritsFrom(this ITypeSymbol symbol, ITypeSymbol? expectedType)IsString(ITypeSymbol?)
public static bool IsString(this ITypeSymbol? symbol)No documentation is available.