src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\Utilities\AbstractSpeculationAnalyzer.cs (25)
102protected abstract TConversion ClassifyConversion(SemanticModel model, TExpressionSyntax expression, ITypeSymbol targetType);
103protected abstract TConversion ClassifyConversion(SemanticModel model, ITypeSymbol originalType, ITypeSymbol targetType);
105protected abstract bool ConversionsAreCompatible(TExpressionSyntax originalExpression, ITypeSymbol originalTargetType, TExpressionSyntax newExpression, ITypeSymbol newTargetType);
106protected abstract bool IsReferenceConversion(Compilation model, ITypeSymbol sourceType, ITypeSymbol targetType);
112SemanticModel model, TForEachStatementSyntax forEach, out IMethodSymbol getEnumeratorMethod, out ITypeSymbol elementType, out ImmutableArray<ILocalSymbol> localVariables);
305private bool ImplicitConversionsAreCompatible(TExpressionSyntax originalExpression, ITypeSymbol originalTargetType, TExpressionSyntax newExpression, ITypeSymbol newTargetType)
740var previousOriginalType = this.OriginalSemanticModel.GetTypeInfo(previousOriginalNode).Type;
741var previousReplacedType = this.SpeculativeSemanticModel.GetTypeInfo(previousReplacedNode).Type;
780GetForEachSymbols(this.OriginalSemanticModel, forEachStatement, out var originalGetEnumerator, out var originalElementType, out var originalLocalVariables);
781GetForEachSymbols(this.SpeculativeSemanticModel, newForEachStatement, out var newGetEnumerator, out var newElementType, out var newLocalVariables);
826var expressionType = this.SpeculativeSemanticModel.GetTypeInfo(newForEachStatementExpression, CancellationToken).ConvertedType;
849var originalThrowExpressionType = this.OriginalSemanticModel.GetTypeInfo(originalThrowExpression).Type;
851var newThrowExpressionType = this.SpeculativeSemanticModel.GetTypeInfo(newThrowExpression).Type;
961var originalTargetType = this.OriginalSemanticModel.GetTypeInfo(originalLeft).Type;
964var newTargetType = this.SpeculativeSemanticModel.GetTypeInfo(newLeft).Type;
997var newReceiverType = newReceiver != null
1036var receiverType = semanticModel.GetTypeInfo(receiver).Type;
1196ITypeSymbol originalTargetType,
1198ITypeSymbol newTargetType,
1213var originalConvertedTypeSymbol = this.OriginalSemanticModel.GetTypeInfo(originalExpression).ConvertedType;
1219var newConvertedTypeSymbol = this.SpeculativeSemanticModel.GetTypeInfo(newExpression).ConvertedType;
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Extensions\Symbols\ITypeSymbolExtensions.cs (101)
26public static bool IsIntegralType([NotNullWhen(returnValue: true)] this ITypeSymbol? type)
29public static bool IsSignedIntegralType([NotNullWhen(returnValue: true)] this ITypeSymbol? type)
32public static bool CanAddNullCheck([NotNullWhen(returnValue: true)] this ITypeSymbol? type)
43public static ImmutableArray<INamedTypeSymbol> GetAllInterfacesIncludingThis(this ITypeSymbol type)
51public static bool IsAbstractClass([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
54public static bool IsSystemVoid([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
57public static bool IsNullable([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
60public static bool IsNonNullableValueType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
64[NotNullWhen(true)] this ITypeSymbol? symbol,
65[NotNullWhen(true)] out ITypeSymbol? underlyingType)
77public static bool IsModuleType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
80public static bool IsInterfaceType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
83public static bool IsDelegateType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
86public static bool IsFunctionPointerType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
89public static bool IsStructType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
96this ITypeSymbol type,
110public static IEnumerable<ITypeSymbol> GetBaseTypesAndThis(this ITypeSymbol? type)
112var current = type;
120public static IEnumerable<INamedTypeSymbol> GetBaseTypes(this ITypeSymbol? type)
130public static IEnumerable<ITypeSymbol> GetContainingTypesAndThis(this ITypeSymbol? type)
132var current = type;
140public static IEnumerable<INamedTypeSymbol> GetContainingTypes(this ITypeSymbol type)
153this ITypeSymbol type, ITypeSymbol baseType, bool includeInterfaces)
166this ITypeSymbol type, ITypeSymbol baseType)
174this ITypeSymbol type, ITypeSymbol baseType)
176var originalBaseType = baseType.OriginalDefinition;
184IEnumerable<ITypeSymbol> baseTypes = (baseType.TypeKind == TypeKind.Interface) ? type.AllInterfaces : type.GetBaseTypes();
191this ITypeSymbol type, ITypeSymbol baseType)
193var originalBaseType = baseType.OriginalDefinition;
213this ITypeSymbol type, ITypeSymbol interfaceType)
215var originalInterfaceType = interfaceType.OriginalDefinition;
220this ITypeSymbol type, ITypeSymbol interfaceType)
225public static bool IsAttribute(this ITypeSymbol symbol)
243public static bool IsFormattableStringOrIFormattable([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
252this ITypeSymbol typeSymbol, bool allowDelegateAndEnumConstraints = false)
280public static bool IsNumericType([NotNullWhen(returnValue: true)] this ITypeSymbol? type)
306public static Accessibility DetermineMinimalAccessibility(this ITypeSymbol typeSymbol)
309public static bool ContainsAnonymousType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
325foreach (var typeArg in type.GetAllTypeArguments())
334public static string CreateParameterName(this ITypeSymbol type, bool capitalize = false)
355private static string GetParameterName(ITypeSymbol? type)
368public static bool IsSpecialType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
399public static bool CanSupportCollectionInitializer(this ITypeSymbol typeSymbol, ISymbol within)
410public static INamedTypeSymbol? GetDelegateType(this ITypeSymbol? typeSymbol, Compilation compilation)
417var typeArgument = ((INamedTypeSymbol)typeSymbol).TypeArguments[0];
430public static IEnumerable<T> GetAccessibleMembersInBaseTypes<T>(this ITypeSymbol containingType, ISymbol within) where T : class, ISymbol
439public static ImmutableArray<T> GetAccessibleMembersInThisAndBaseTypes<T>(this ITypeSymbol? containingType, ISymbol within) where T : class, ISymbol
449public static ImmutableArray<T> GetAccessibleMembersInThisAndBaseTypes<T>(this ITypeSymbol? containingType, string memberName, ISymbol within) where T : class, ISymbol
459public static bool? AreMoreSpecificThan(this IList<ITypeSymbol> t1, IList<ITypeSymbol> t2)
494public static IEnumerable<T> SelectAccessibleMembers<T>(this IEnumerable<ITypeSymbol>? types, ISymbol within) where T : class, ISymbol
504private static IEnumerable<T> SelectAccessibleMembers<T>(this IEnumerable<ITypeSymbol>? types, string memberName, ISymbol within) where T : class, ISymbol
514private static bool? IsMoreSpecificThan(this ITypeSymbol t1, ITypeSymbol t2)
592public static bool IsOrDerivesFromExceptionType([NotNullWhen(returnValue: true)] this ITypeSymbol? type, Compilation compilation)
599foreach (var baseType in type.GetBaseTypesAndThis())
610foreach (var constraint in ((ITypeParameterSymbol)type).ConstraintTypes)
625public static bool IsEnumType([NotNullWhen(true)] this ITypeSymbol? type)
628public static bool IsEnumType([NotNullWhen(true)] this ITypeSymbol? type, [NotNullWhen(true)] out INamedTypeSymbol? enumType)
640public static bool? IsMutableValueType(this ITypeSymbol type)
642if (type.IsNullable(out var underlyingType))
721static bool IsWellKnownImmutableValueType(ITypeSymbol type)
754public static bool IsDisposable([NotNullWhen(returnValue: true)] this ITypeSymbol? type, [NotNullWhen(returnValue: true)] ITypeSymbol? iDisposableType)
759public static ITypeSymbol WithNullableAnnotationFrom(this ITypeSymbol type, ITypeSymbol symbolForNullableAnnotation)
763public static ITypeSymbol? RemoveNullableIfPresent(this ITypeSymbol? symbol)
765if (symbol.IsNullable(out var underlyingType))
773public static bool IsSpanOrReadOnlySpan([NotNullWhen(true)] this ITypeSymbol? type)
776public static bool IsSpan([NotNullWhen(true)] this ITypeSymbol? type)
792public static bool IsInlineArray([NotNullWhen(true)] this ITypeSymbol? type)
797public static ITypeSymbol? RemoveUnavailableTypeParameters(
798this ITypeSymbol? type,
806private static ITypeSymbol? RemoveUnavailableTypeParameters(
807this ITypeSymbol? type,
815public static ITypeSymbol? RemoveAnonymousTypes(
816this ITypeSymbol? type,
823public static ITypeSymbol? RemoveUnnamedErrorTypes(
824this ITypeSymbol? type,
831this ITypeSymbol? type, ArrayBuilder<ITypeParameterSymbol> result)
837this ITypeSymbol? type, ArrayBuilder<ITypeParameterSymbol> result)
843this ITypeSymbol? type, ArrayBuilder<ITypeParameterSymbol> result, bool onlyMethodTypeParameters)
852public static IList<ITypeParameterSymbol> GetReferencedTypeParameters(this ITypeSymbol? type)
860public static ITypeSymbol? SubstituteTypes<TType1, TType2>(
861this ITypeSymbol? type,
864where TType1 : ITypeSymbol
865where TType2 : ITypeSymbol
871public static ITypeSymbol? SubstituteTypes<TType1, TType2>(
872this ITypeSymbol? type,
875where TType1 : ITypeSymbol
876where TType2 : ITypeSymbol
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\Core\CodeGeneration\CodeGenerationSymbolFactory.cs (18)
30DeclarationModifiers modifiers, ITypeSymbol type,
47ITypeSymbol type,
79ITypeSymbol type, RefKind refKind, ImmutableArray<IPropertySymbol> explicitInterfaceImplementations, string name,
106ITypeSymbol type, string name,
152ITypeSymbol? returnType,
174ITypeSymbol? returnType,
195ITypeSymbol returnType,
220ITypeSymbol toType,
248ITypeSymbol toType,
264public static IParameterSymbol CreateParameterSymbol(ITypeSymbol type, string name)
267public static IParameterSymbol CreateParameterSymbol(RefKind refKind, ITypeSymbol type, string name)
277ImmutableArray<AttributeData> attributes, RefKind refKind, bool isParams, ITypeSymbol type, string name, bool isOptional = false, bool hasDefaultValue = false, object? defaultValue = null)
290ITypeSymbol? type = null,
331ImmutableArray<ITypeSymbol> constraintTypes,
347public static IPointerTypeSymbol CreatePointerTypeSymbol(ITypeSymbol pointedAtType)
353public static IArrayTypeSymbol CreateArrayTypeSymbol(ITypeSymbol elementType, int rank = 1, NullableAnnotation nullableAnnotation = NullableAnnotation.None)
463ITypeSymbol returnType,
520ITypeSymbol? returnType = null,
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\Core\CodeGeneration\Symbols\CodeGenerationArrayTypeSymbol.cs (2)
10internal sealed class CodeGenerationArrayTypeSymbol(ITypeSymbol elementType, int rank, NullableAnnotation nullableAnnotation) : CodeGenerationTypeSymbol(null, null, default, Accessibility.NotApplicable, default, string.Empty, SpecialType.None, nullableAnnotation), IArrayTypeSymbol
12public ITypeSymbol ElementType { get; } = elementType;
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\Core\CodeGeneration\Symbols\CodeGenerationConversionSymbol.cs (1)
15ITypeSymbol toType,
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\Core\CodeGeneration\Symbols\CodeGenerationOperatorSymbol.cs (1)
15ITypeSymbol returnType,
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\Utilities\AbstractSpeculationAnalyzer.cs (25)
102protected abstract TConversion ClassifyConversion(SemanticModel model, TExpressionSyntax expression, ITypeSymbol targetType);
103protected abstract TConversion ClassifyConversion(SemanticModel model, ITypeSymbol originalType, ITypeSymbol targetType);
105protected abstract bool ConversionsAreCompatible(TExpressionSyntax originalExpression, ITypeSymbol originalTargetType, TExpressionSyntax newExpression, ITypeSymbol newTargetType);
106protected abstract bool IsReferenceConversion(Compilation model, ITypeSymbol sourceType, ITypeSymbol targetType);
112SemanticModel model, TForEachStatementSyntax forEach, out IMethodSymbol getEnumeratorMethod, out ITypeSymbol elementType, out ImmutableArray<ILocalSymbol> localVariables);
305private bool ImplicitConversionsAreCompatible(TExpressionSyntax originalExpression, ITypeSymbol originalTargetType, TExpressionSyntax newExpression, ITypeSymbol newTargetType)
740var previousOriginalType = this.OriginalSemanticModel.GetTypeInfo(previousOriginalNode).Type;
741var previousReplacedType = this.SpeculativeSemanticModel.GetTypeInfo(previousReplacedNode).Type;
780GetForEachSymbols(this.OriginalSemanticModel, forEachStatement, out var originalGetEnumerator, out var originalElementType, out var originalLocalVariables);
781GetForEachSymbols(this.SpeculativeSemanticModel, newForEachStatement, out var newGetEnumerator, out var newElementType, out var newLocalVariables);
826var expressionType = this.SpeculativeSemanticModel.GetTypeInfo(newForEachStatementExpression, CancellationToken).ConvertedType;
849var originalThrowExpressionType = this.OriginalSemanticModel.GetTypeInfo(originalThrowExpression).Type;
851var newThrowExpressionType = this.SpeculativeSemanticModel.GetTypeInfo(newThrowExpression).Type;
961var originalTargetType = this.OriginalSemanticModel.GetTypeInfo(originalLeft).Type;
964var newTargetType = this.SpeculativeSemanticModel.GetTypeInfo(newLeft).Type;
997var newReceiverType = newReceiver != null
1036var receiverType = semanticModel.GetTypeInfo(receiver).Type;
1196ITypeSymbol originalTargetType,
1198ITypeSymbol newTargetType,
1213var originalConvertedTypeSymbol = this.OriginalSemanticModel.GetTypeInfo(originalExpression).ConvertedType;
1219var newConvertedTypeSymbol = this.SpeculativeSemanticModel.GetTypeInfo(newExpression).ConvertedType;
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Extensions\Symbols\ITypeSymbolExtensions.cs (101)
26public static bool IsIntegralType([NotNullWhen(returnValue: true)] this ITypeSymbol? type)
29public static bool IsSignedIntegralType([NotNullWhen(returnValue: true)] this ITypeSymbol? type)
32public static bool CanAddNullCheck([NotNullWhen(returnValue: true)] this ITypeSymbol? type)
43public static ImmutableArray<INamedTypeSymbol> GetAllInterfacesIncludingThis(this ITypeSymbol type)
51public static bool IsAbstractClass([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
54public static bool IsSystemVoid([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
57public static bool IsNullable([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
60public static bool IsNonNullableValueType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
64[NotNullWhen(true)] this ITypeSymbol? symbol,
65[NotNullWhen(true)] out ITypeSymbol? underlyingType)
77public static bool IsModuleType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
80public static bool IsInterfaceType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
83public static bool IsDelegateType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
86public static bool IsFunctionPointerType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
89public static bool IsStructType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
96this ITypeSymbol type,
110public static IEnumerable<ITypeSymbol> GetBaseTypesAndThis(this ITypeSymbol? type)
112var current = type;
120public static IEnumerable<INamedTypeSymbol> GetBaseTypes(this ITypeSymbol? type)
130public static IEnumerable<ITypeSymbol> GetContainingTypesAndThis(this ITypeSymbol? type)
132var current = type;
140public static IEnumerable<INamedTypeSymbol> GetContainingTypes(this ITypeSymbol type)
153this ITypeSymbol type, ITypeSymbol baseType, bool includeInterfaces)
166this ITypeSymbol type, ITypeSymbol baseType)
174this ITypeSymbol type, ITypeSymbol baseType)
176var originalBaseType = baseType.OriginalDefinition;
184IEnumerable<ITypeSymbol> baseTypes = (baseType.TypeKind == TypeKind.Interface) ? type.AllInterfaces : type.GetBaseTypes();
191this ITypeSymbol type, ITypeSymbol baseType)
193var originalBaseType = baseType.OriginalDefinition;
213this ITypeSymbol type, ITypeSymbol interfaceType)
215var originalInterfaceType = interfaceType.OriginalDefinition;
220this ITypeSymbol type, ITypeSymbol interfaceType)
225public static bool IsAttribute(this ITypeSymbol symbol)
243public static bool IsFormattableStringOrIFormattable([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
252this ITypeSymbol typeSymbol, bool allowDelegateAndEnumConstraints = false)
280public static bool IsNumericType([NotNullWhen(returnValue: true)] this ITypeSymbol? type)
306public static Accessibility DetermineMinimalAccessibility(this ITypeSymbol typeSymbol)
309public static bool ContainsAnonymousType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
325foreach (var typeArg in type.GetAllTypeArguments())
334public static string CreateParameterName(this ITypeSymbol type, bool capitalize = false)
355private static string GetParameterName(ITypeSymbol? type)
368public static bool IsSpecialType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
399public static bool CanSupportCollectionInitializer(this ITypeSymbol typeSymbol, ISymbol within)
410public static INamedTypeSymbol? GetDelegateType(this ITypeSymbol? typeSymbol, Compilation compilation)
417var typeArgument = ((INamedTypeSymbol)typeSymbol).TypeArguments[0];
430public static IEnumerable<T> GetAccessibleMembersInBaseTypes<T>(this ITypeSymbol containingType, ISymbol within) where T : class, ISymbol
439public static ImmutableArray<T> GetAccessibleMembersInThisAndBaseTypes<T>(this ITypeSymbol? containingType, ISymbol within) where T : class, ISymbol
449public static ImmutableArray<T> GetAccessibleMembersInThisAndBaseTypes<T>(this ITypeSymbol? containingType, string memberName, ISymbol within) where T : class, ISymbol
459public static bool? AreMoreSpecificThan(this IList<ITypeSymbol> t1, IList<ITypeSymbol> t2)
494public static IEnumerable<T> SelectAccessibleMembers<T>(this IEnumerable<ITypeSymbol>? types, ISymbol within) where T : class, ISymbol
504private static IEnumerable<T> SelectAccessibleMembers<T>(this IEnumerable<ITypeSymbol>? types, string memberName, ISymbol within) where T : class, ISymbol
514private static bool? IsMoreSpecificThan(this ITypeSymbol t1, ITypeSymbol t2)
592public static bool IsOrDerivesFromExceptionType([NotNullWhen(returnValue: true)] this ITypeSymbol? type, Compilation compilation)
599foreach (var baseType in type.GetBaseTypesAndThis())
610foreach (var constraint in ((ITypeParameterSymbol)type).ConstraintTypes)
625public static bool IsEnumType([NotNullWhen(true)] this ITypeSymbol? type)
628public static bool IsEnumType([NotNullWhen(true)] this ITypeSymbol? type, [NotNullWhen(true)] out INamedTypeSymbol? enumType)
640public static bool? IsMutableValueType(this ITypeSymbol type)
642if (type.IsNullable(out var underlyingType))
721static bool IsWellKnownImmutableValueType(ITypeSymbol type)
754public static bool IsDisposable([NotNullWhen(returnValue: true)] this ITypeSymbol? type, [NotNullWhen(returnValue: true)] ITypeSymbol? iDisposableType)
759public static ITypeSymbol WithNullableAnnotationFrom(this ITypeSymbol type, ITypeSymbol symbolForNullableAnnotation)
763public static ITypeSymbol? RemoveNullableIfPresent(this ITypeSymbol? symbol)
765if (symbol.IsNullable(out var underlyingType))
773public static bool IsSpanOrReadOnlySpan([NotNullWhen(true)] this ITypeSymbol? type)
776public static bool IsSpan([NotNullWhen(true)] this ITypeSymbol? type)
792public static bool IsInlineArray([NotNullWhen(true)] this ITypeSymbol? type)
797public static ITypeSymbol? RemoveUnavailableTypeParameters(
798this ITypeSymbol? type,
806private static ITypeSymbol? RemoveUnavailableTypeParameters(
807this ITypeSymbol? type,
815public static ITypeSymbol? RemoveAnonymousTypes(
816this ITypeSymbol? type,
823public static ITypeSymbol? RemoveUnnamedErrorTypes(
824this ITypeSymbol? type,
831this ITypeSymbol? type, ArrayBuilder<ITypeParameterSymbol> result)
837this ITypeSymbol? type, ArrayBuilder<ITypeParameterSymbol> result)
843this ITypeSymbol? type, ArrayBuilder<ITypeParameterSymbol> result, bool onlyMethodTypeParameters)
852public static IList<ITypeParameterSymbol> GetReferencedTypeParameters(this ITypeSymbol? type)
860public static ITypeSymbol? SubstituteTypes<TType1, TType2>(
861this ITypeSymbol? type,
864where TType1 : ITypeSymbol
865where TType2 : ITypeSymbol
871public static ITypeSymbol? SubstituteTypes<TType1, TType2>(
872this ITypeSymbol? type,
875where TType1 : ITypeSymbol
876where TType2 : ITypeSymbol
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\Utilities\AbstractSpeculationAnalyzer.cs (25)
102protected abstract TConversion ClassifyConversion(SemanticModel model, TExpressionSyntax expression, ITypeSymbol targetType);
103protected abstract TConversion ClassifyConversion(SemanticModel model, ITypeSymbol originalType, ITypeSymbol targetType);
105protected abstract bool ConversionsAreCompatible(TExpressionSyntax originalExpression, ITypeSymbol originalTargetType, TExpressionSyntax newExpression, ITypeSymbol newTargetType);
106protected abstract bool IsReferenceConversion(Compilation model, ITypeSymbol sourceType, ITypeSymbol targetType);
112SemanticModel model, TForEachStatementSyntax forEach, out IMethodSymbol getEnumeratorMethod, out ITypeSymbol elementType, out ImmutableArray<ILocalSymbol> localVariables);
305private bool ImplicitConversionsAreCompatible(TExpressionSyntax originalExpression, ITypeSymbol originalTargetType, TExpressionSyntax newExpression, ITypeSymbol newTargetType)
740var previousOriginalType = this.OriginalSemanticModel.GetTypeInfo(previousOriginalNode).Type;
741var previousReplacedType = this.SpeculativeSemanticModel.GetTypeInfo(previousReplacedNode).Type;
780GetForEachSymbols(this.OriginalSemanticModel, forEachStatement, out var originalGetEnumerator, out var originalElementType, out var originalLocalVariables);
781GetForEachSymbols(this.SpeculativeSemanticModel, newForEachStatement, out var newGetEnumerator, out var newElementType, out var newLocalVariables);
826var expressionType = this.SpeculativeSemanticModel.GetTypeInfo(newForEachStatementExpression, CancellationToken).ConvertedType;
849var originalThrowExpressionType = this.OriginalSemanticModel.GetTypeInfo(originalThrowExpression).Type;
851var newThrowExpressionType = this.SpeculativeSemanticModel.GetTypeInfo(newThrowExpression).Type;
961var originalTargetType = this.OriginalSemanticModel.GetTypeInfo(originalLeft).Type;
964var newTargetType = this.SpeculativeSemanticModel.GetTypeInfo(newLeft).Type;
997var newReceiverType = newReceiver != null
1036var receiverType = semanticModel.GetTypeInfo(receiver).Type;
1196ITypeSymbol originalTargetType,
1198ITypeSymbol newTargetType,
1213var originalConvertedTypeSymbol = this.OriginalSemanticModel.GetTypeInfo(originalExpression).ConvertedType;
1219var newConvertedTypeSymbol = this.SpeculativeSemanticModel.GetTypeInfo(newExpression).ConvertedType;
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Extensions\Symbols\ITypeSymbolExtensions.cs (101)
26public static bool IsIntegralType([NotNullWhen(returnValue: true)] this ITypeSymbol? type)
29public static bool IsSignedIntegralType([NotNullWhen(returnValue: true)] this ITypeSymbol? type)
32public static bool CanAddNullCheck([NotNullWhen(returnValue: true)] this ITypeSymbol? type)
43public static ImmutableArray<INamedTypeSymbol> GetAllInterfacesIncludingThis(this ITypeSymbol type)
51public static bool IsAbstractClass([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
54public static bool IsSystemVoid([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
57public static bool IsNullable([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
60public static bool IsNonNullableValueType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
64[NotNullWhen(true)] this ITypeSymbol? symbol,
65[NotNullWhen(true)] out ITypeSymbol? underlyingType)
77public static bool IsModuleType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
80public static bool IsInterfaceType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
83public static bool IsDelegateType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
86public static bool IsFunctionPointerType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
89public static bool IsStructType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
96this ITypeSymbol type,
110public static IEnumerable<ITypeSymbol> GetBaseTypesAndThis(this ITypeSymbol? type)
112var current = type;
120public static IEnumerable<INamedTypeSymbol> GetBaseTypes(this ITypeSymbol? type)
130public static IEnumerable<ITypeSymbol> GetContainingTypesAndThis(this ITypeSymbol? type)
132var current = type;
140public static IEnumerable<INamedTypeSymbol> GetContainingTypes(this ITypeSymbol type)
153this ITypeSymbol type, ITypeSymbol baseType, bool includeInterfaces)
166this ITypeSymbol type, ITypeSymbol baseType)
174this ITypeSymbol type, ITypeSymbol baseType)
176var originalBaseType = baseType.OriginalDefinition;
184IEnumerable<ITypeSymbol> baseTypes = (baseType.TypeKind == TypeKind.Interface) ? type.AllInterfaces : type.GetBaseTypes();
191this ITypeSymbol type, ITypeSymbol baseType)
193var originalBaseType = baseType.OriginalDefinition;
213this ITypeSymbol type, ITypeSymbol interfaceType)
215var originalInterfaceType = interfaceType.OriginalDefinition;
220this ITypeSymbol type, ITypeSymbol interfaceType)
225public static bool IsAttribute(this ITypeSymbol symbol)
243public static bool IsFormattableStringOrIFormattable([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
252this ITypeSymbol typeSymbol, bool allowDelegateAndEnumConstraints = false)
280public static bool IsNumericType([NotNullWhen(returnValue: true)] this ITypeSymbol? type)
306public static Accessibility DetermineMinimalAccessibility(this ITypeSymbol typeSymbol)
309public static bool ContainsAnonymousType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
325foreach (var typeArg in type.GetAllTypeArguments())
334public static string CreateParameterName(this ITypeSymbol type, bool capitalize = false)
355private static string GetParameterName(ITypeSymbol? type)
368public static bool IsSpecialType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
399public static bool CanSupportCollectionInitializer(this ITypeSymbol typeSymbol, ISymbol within)
410public static INamedTypeSymbol? GetDelegateType(this ITypeSymbol? typeSymbol, Compilation compilation)
417var typeArgument = ((INamedTypeSymbol)typeSymbol).TypeArguments[0];
430public static IEnumerable<T> GetAccessibleMembersInBaseTypes<T>(this ITypeSymbol containingType, ISymbol within) where T : class, ISymbol
439public static ImmutableArray<T> GetAccessibleMembersInThisAndBaseTypes<T>(this ITypeSymbol? containingType, ISymbol within) where T : class, ISymbol
449public static ImmutableArray<T> GetAccessibleMembersInThisAndBaseTypes<T>(this ITypeSymbol? containingType, string memberName, ISymbol within) where T : class, ISymbol
459public static bool? AreMoreSpecificThan(this IList<ITypeSymbol> t1, IList<ITypeSymbol> t2)
494public static IEnumerable<T> SelectAccessibleMembers<T>(this IEnumerable<ITypeSymbol>? types, ISymbol within) where T : class, ISymbol
504private static IEnumerable<T> SelectAccessibleMembers<T>(this IEnumerable<ITypeSymbol>? types, string memberName, ISymbol within) where T : class, ISymbol
514private static bool? IsMoreSpecificThan(this ITypeSymbol t1, ITypeSymbol t2)
592public static bool IsOrDerivesFromExceptionType([NotNullWhen(returnValue: true)] this ITypeSymbol? type, Compilation compilation)
599foreach (var baseType in type.GetBaseTypesAndThis())
610foreach (var constraint in ((ITypeParameterSymbol)type).ConstraintTypes)
625public static bool IsEnumType([NotNullWhen(true)] this ITypeSymbol? type)
628public static bool IsEnumType([NotNullWhen(true)] this ITypeSymbol? type, [NotNullWhen(true)] out INamedTypeSymbol? enumType)
640public static bool? IsMutableValueType(this ITypeSymbol type)
642if (type.IsNullable(out var underlyingType))
721static bool IsWellKnownImmutableValueType(ITypeSymbol type)
754public static bool IsDisposable([NotNullWhen(returnValue: true)] this ITypeSymbol? type, [NotNullWhen(returnValue: true)] ITypeSymbol? iDisposableType)
759public static ITypeSymbol WithNullableAnnotationFrom(this ITypeSymbol type, ITypeSymbol symbolForNullableAnnotation)
763public static ITypeSymbol? RemoveNullableIfPresent(this ITypeSymbol? symbol)
765if (symbol.IsNullable(out var underlyingType))
773public static bool IsSpanOrReadOnlySpan([NotNullWhen(true)] this ITypeSymbol? type)
776public static bool IsSpan([NotNullWhen(true)] this ITypeSymbol? type)
792public static bool IsInlineArray([NotNullWhen(true)] this ITypeSymbol? type)
797public static ITypeSymbol? RemoveUnavailableTypeParameters(
798this ITypeSymbol? type,
806private static ITypeSymbol? RemoveUnavailableTypeParameters(
807this ITypeSymbol? type,
815public static ITypeSymbol? RemoveAnonymousTypes(
816this ITypeSymbol? type,
823public static ITypeSymbol? RemoveUnnamedErrorTypes(
824this ITypeSymbol? type,
831this ITypeSymbol? type, ArrayBuilder<ITypeParameterSymbol> result)
837this ITypeSymbol? type, ArrayBuilder<ITypeParameterSymbol> result)
843this ITypeSymbol? type, ArrayBuilder<ITypeParameterSymbol> result, bool onlyMethodTypeParameters)
852public static IList<ITypeParameterSymbol> GetReferencedTypeParameters(this ITypeSymbol? type)
860public static ITypeSymbol? SubstituteTypes<TType1, TType2>(
861this ITypeSymbol? type,
864where TType1 : ITypeSymbol
865where TType2 : ITypeSymbol
871public static ITypeSymbol? SubstituteTypes<TType1, TType2>(
872this ITypeSymbol? type,
875where TType1 : ITypeSymbol
876where TType2 : ITypeSymbol
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\Utilities\AbstractSpeculationAnalyzer.cs (25)
102protected abstract TConversion ClassifyConversion(SemanticModel model, TExpressionSyntax expression, ITypeSymbol targetType);
103protected abstract TConversion ClassifyConversion(SemanticModel model, ITypeSymbol originalType, ITypeSymbol targetType);
105protected abstract bool ConversionsAreCompatible(TExpressionSyntax originalExpression, ITypeSymbol originalTargetType, TExpressionSyntax newExpression, ITypeSymbol newTargetType);
106protected abstract bool IsReferenceConversion(Compilation model, ITypeSymbol sourceType, ITypeSymbol targetType);
112SemanticModel model, TForEachStatementSyntax forEach, out IMethodSymbol getEnumeratorMethod, out ITypeSymbol elementType, out ImmutableArray<ILocalSymbol> localVariables);
305private bool ImplicitConversionsAreCompatible(TExpressionSyntax originalExpression, ITypeSymbol originalTargetType, TExpressionSyntax newExpression, ITypeSymbol newTargetType)
740var previousOriginalType = this.OriginalSemanticModel.GetTypeInfo(previousOriginalNode).Type;
741var previousReplacedType = this.SpeculativeSemanticModel.GetTypeInfo(previousReplacedNode).Type;
780GetForEachSymbols(this.OriginalSemanticModel, forEachStatement, out var originalGetEnumerator, out var originalElementType, out var originalLocalVariables);
781GetForEachSymbols(this.SpeculativeSemanticModel, newForEachStatement, out var newGetEnumerator, out var newElementType, out var newLocalVariables);
826var expressionType = this.SpeculativeSemanticModel.GetTypeInfo(newForEachStatementExpression, CancellationToken).ConvertedType;
849var originalThrowExpressionType = this.OriginalSemanticModel.GetTypeInfo(originalThrowExpression).Type;
851var newThrowExpressionType = this.SpeculativeSemanticModel.GetTypeInfo(newThrowExpression).Type;
961var originalTargetType = this.OriginalSemanticModel.GetTypeInfo(originalLeft).Type;
964var newTargetType = this.SpeculativeSemanticModel.GetTypeInfo(newLeft).Type;
997var newReceiverType = newReceiver != null
1036var receiverType = semanticModel.GetTypeInfo(receiver).Type;
1196ITypeSymbol originalTargetType,
1198ITypeSymbol newTargetType,
1213var originalConvertedTypeSymbol = this.OriginalSemanticModel.GetTypeInfo(originalExpression).ConvertedType;
1219var newConvertedTypeSymbol = this.SpeculativeSemanticModel.GetTypeInfo(newExpression).ConvertedType;
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Extensions\Symbols\ITypeSymbolExtensions.cs (101)
26public static bool IsIntegralType([NotNullWhen(returnValue: true)] this ITypeSymbol? type)
29public static bool IsSignedIntegralType([NotNullWhen(returnValue: true)] this ITypeSymbol? type)
32public static bool CanAddNullCheck([NotNullWhen(returnValue: true)] this ITypeSymbol? type)
43public static ImmutableArray<INamedTypeSymbol> GetAllInterfacesIncludingThis(this ITypeSymbol type)
51public static bool IsAbstractClass([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
54public static bool IsSystemVoid([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
57public static bool IsNullable([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
60public static bool IsNonNullableValueType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
64[NotNullWhen(true)] this ITypeSymbol? symbol,
65[NotNullWhen(true)] out ITypeSymbol? underlyingType)
77public static bool IsModuleType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
80public static bool IsInterfaceType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
83public static bool IsDelegateType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
86public static bool IsFunctionPointerType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
89public static bool IsStructType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
96this ITypeSymbol type,
110public static IEnumerable<ITypeSymbol> GetBaseTypesAndThis(this ITypeSymbol? type)
112var current = type;
120public static IEnumerable<INamedTypeSymbol> GetBaseTypes(this ITypeSymbol? type)
130public static IEnumerable<ITypeSymbol> GetContainingTypesAndThis(this ITypeSymbol? type)
132var current = type;
140public static IEnumerable<INamedTypeSymbol> GetContainingTypes(this ITypeSymbol type)
153this ITypeSymbol type, ITypeSymbol baseType, bool includeInterfaces)
166this ITypeSymbol type, ITypeSymbol baseType)
174this ITypeSymbol type, ITypeSymbol baseType)
176var originalBaseType = baseType.OriginalDefinition;
184IEnumerable<ITypeSymbol> baseTypes = (baseType.TypeKind == TypeKind.Interface) ? type.AllInterfaces : type.GetBaseTypes();
191this ITypeSymbol type, ITypeSymbol baseType)
193var originalBaseType = baseType.OriginalDefinition;
213this ITypeSymbol type, ITypeSymbol interfaceType)
215var originalInterfaceType = interfaceType.OriginalDefinition;
220this ITypeSymbol type, ITypeSymbol interfaceType)
225public static bool IsAttribute(this ITypeSymbol symbol)
243public static bool IsFormattableStringOrIFormattable([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
252this ITypeSymbol typeSymbol, bool allowDelegateAndEnumConstraints = false)
280public static bool IsNumericType([NotNullWhen(returnValue: true)] this ITypeSymbol? type)
306public static Accessibility DetermineMinimalAccessibility(this ITypeSymbol typeSymbol)
309public static bool ContainsAnonymousType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
325foreach (var typeArg in type.GetAllTypeArguments())
334public static string CreateParameterName(this ITypeSymbol type, bool capitalize = false)
355private static string GetParameterName(ITypeSymbol? type)
368public static bool IsSpecialType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
399public static bool CanSupportCollectionInitializer(this ITypeSymbol typeSymbol, ISymbol within)
410public static INamedTypeSymbol? GetDelegateType(this ITypeSymbol? typeSymbol, Compilation compilation)
417var typeArgument = ((INamedTypeSymbol)typeSymbol).TypeArguments[0];
430public static IEnumerable<T> GetAccessibleMembersInBaseTypes<T>(this ITypeSymbol containingType, ISymbol within) where T : class, ISymbol
439public static ImmutableArray<T> GetAccessibleMembersInThisAndBaseTypes<T>(this ITypeSymbol? containingType, ISymbol within) where T : class, ISymbol
449public static ImmutableArray<T> GetAccessibleMembersInThisAndBaseTypes<T>(this ITypeSymbol? containingType, string memberName, ISymbol within) where T : class, ISymbol
459public static bool? AreMoreSpecificThan(this IList<ITypeSymbol> t1, IList<ITypeSymbol> t2)
494public static IEnumerable<T> SelectAccessibleMembers<T>(this IEnumerable<ITypeSymbol>? types, ISymbol within) where T : class, ISymbol
504private static IEnumerable<T> SelectAccessibleMembers<T>(this IEnumerable<ITypeSymbol>? types, string memberName, ISymbol within) where T : class, ISymbol
514private static bool? IsMoreSpecificThan(this ITypeSymbol t1, ITypeSymbol t2)
592public static bool IsOrDerivesFromExceptionType([NotNullWhen(returnValue: true)] this ITypeSymbol? type, Compilation compilation)
599foreach (var baseType in type.GetBaseTypesAndThis())
610foreach (var constraint in ((ITypeParameterSymbol)type).ConstraintTypes)
625public static bool IsEnumType([NotNullWhen(true)] this ITypeSymbol? type)
628public static bool IsEnumType([NotNullWhen(true)] this ITypeSymbol? type, [NotNullWhen(true)] out INamedTypeSymbol? enumType)
640public static bool? IsMutableValueType(this ITypeSymbol type)
642if (type.IsNullable(out var underlyingType))
721static bool IsWellKnownImmutableValueType(ITypeSymbol type)
754public static bool IsDisposable([NotNullWhen(returnValue: true)] this ITypeSymbol? type, [NotNullWhen(returnValue: true)] ITypeSymbol? iDisposableType)
759public static ITypeSymbol WithNullableAnnotationFrom(this ITypeSymbol type, ITypeSymbol symbolForNullableAnnotation)
763public static ITypeSymbol? RemoveNullableIfPresent(this ITypeSymbol? symbol)
765if (symbol.IsNullable(out var underlyingType))
773public static bool IsSpanOrReadOnlySpan([NotNullWhen(true)] this ITypeSymbol? type)
776public static bool IsSpan([NotNullWhen(true)] this ITypeSymbol? type)
792public static bool IsInlineArray([NotNullWhen(true)] this ITypeSymbol? type)
797public static ITypeSymbol? RemoveUnavailableTypeParameters(
798this ITypeSymbol? type,
806private static ITypeSymbol? RemoveUnavailableTypeParameters(
807this ITypeSymbol? type,
815public static ITypeSymbol? RemoveAnonymousTypes(
816this ITypeSymbol? type,
823public static ITypeSymbol? RemoveUnnamedErrorTypes(
824this ITypeSymbol? type,
831this ITypeSymbol? type, ArrayBuilder<ITypeParameterSymbol> result)
837this ITypeSymbol? type, ArrayBuilder<ITypeParameterSymbol> result)
843this ITypeSymbol? type, ArrayBuilder<ITypeParameterSymbol> result, bool onlyMethodTypeParameters)
852public static IList<ITypeParameterSymbol> GetReferencedTypeParameters(this ITypeSymbol? type)
860public static ITypeSymbol? SubstituteTypes<TType1, TType2>(
861this ITypeSymbol? type,
864where TType1 : ITypeSymbol
865where TType2 : ITypeSymbol
871public static ITypeSymbol? SubstituteTypes<TType1, TType2>(
872this ITypeSymbol? type,
875where TType1 : ITypeSymbol
876where TType2 : ITypeSymbol
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\Core\CodeGeneration\CodeGenerationSymbolFactory.cs (18)
30DeclarationModifiers modifiers, ITypeSymbol type,
47ITypeSymbol type,
79ITypeSymbol type, RefKind refKind, ImmutableArray<IPropertySymbol> explicitInterfaceImplementations, string name,
106ITypeSymbol type, string name,
152ITypeSymbol? returnType,
174ITypeSymbol? returnType,
195ITypeSymbol returnType,
220ITypeSymbol toType,
248ITypeSymbol toType,
264public static IParameterSymbol CreateParameterSymbol(ITypeSymbol type, string name)
267public static IParameterSymbol CreateParameterSymbol(RefKind refKind, ITypeSymbol type, string name)
277ImmutableArray<AttributeData> attributes, RefKind refKind, bool isParams, ITypeSymbol type, string name, bool isOptional = false, bool hasDefaultValue = false, object? defaultValue = null)
290ITypeSymbol? type = null,
331ImmutableArray<ITypeSymbol> constraintTypes,
347public static IPointerTypeSymbol CreatePointerTypeSymbol(ITypeSymbol pointedAtType)
353public static IArrayTypeSymbol CreateArrayTypeSymbol(ITypeSymbol elementType, int rank = 1, NullableAnnotation nullableAnnotation = NullableAnnotation.None)
463ITypeSymbol returnType,
520ITypeSymbol? returnType = null,
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\Core\CodeGeneration\Symbols\CodeGenerationArrayTypeSymbol.cs (2)
10internal sealed class CodeGenerationArrayTypeSymbol(ITypeSymbol elementType, int rank, NullableAnnotation nullableAnnotation) : CodeGenerationTypeSymbol(null, null, default, Accessibility.NotApplicable, default, string.Empty, SpecialType.None, nullableAnnotation), IArrayTypeSymbol
12public ITypeSymbol ElementType { get; } = elementType;
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\Core\CodeGeneration\Symbols\CodeGenerationConversionSymbol.cs (1)
15ITypeSymbol toType,
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\Core\CodeGeneration\Symbols\CodeGenerationOperatorSymbol.cs (1)
15ITypeSymbol returnType,
src\RoslynAnalyzers\Utilities\FlowAnalysis\FlowAnalysis\Analysis\PointsToAnalysis\PointsToAnalysis.PointsToDataFlowOperationVisitor.cs (8)
171protected override PointsToAbstractValue GetAbstractDefaultValue(ITypeSymbol? type) => !PointsToAnalysis.ShouldBeTracked(type, IsDisposable) ? PointsToAbstractValue.NoLocation : PointsToAbstractValue.NullLocation;
439ITypeSymbol targetType,
445Func<ITypeSymbol?, bool> isDisposable,
505ITypeSymbol targetType,
740protected override void SetAbstractValueForArrayElementInitializer(IArrayCreationOperation arrayCreation, ImmutableArray<AbstractIndex> indices, ITypeSymbol elementType, IOperation initializer, PointsToAbstractValue value)
1052private NullAbstractValue GetNullStateBasedOnInstanceOrReferenceValue(IOperation? referenceOrInstance, ITypeSymbol? operationType, NullAbstractValue defaultValue)
1253public override PointsToAbstractValue ComputeValueForCompoundAssignment(ICompoundAssignmentOperation operation, PointsToAbstractValue targetValue, PointsToAbstractValue assignedValue, ITypeSymbol? targetType, ITypeSymbol? assignedValueType)
src\RoslynAnalyzers\Utilities\FlowAnalysis\FlowAnalysis\Analysis\PointsToAnalysis\PointsToAnalysisData.cs (6)
20private readonly Func<ITypeSymbol?, bool> _isDisposable;
22internal PointsToAnalysisData(Func<ITypeSymbol?, bool> isDisposable)
27internal PointsToAnalysisData(IDictionary<AnalysisEntity, PointsToAbstractValue> fromData, Func<ITypeSymbol?, bool> isDisposable)
41Func<ITypeSymbol?, bool> isDisposable)
122internal static void AssertValidPointsToAnalysisData(IDictionary<AnalysisEntity, PointsToAbstractValue> map, Func<ITypeSymbol?, bool> isDisposable)
139Func<ITypeSymbol?, bool> isDisposable)
src\RoslynAnalyzers\Utilities\FlowAnalysis\FlowAnalysis\Analysis\ValueContentAnalysis\ValueContentAbstractValue.cs (9)
43internal static ValueContentAbstractValue Create(object literal, ITypeSymbol type)
120internal static bool IsSupportedType(ITypeSymbol type, [NotNullWhen(returnValue: true)] out ITypeSymbol? valueTypeSymbol)
256ITypeSymbol? leftType,
257ITypeSymbol? rightType,
258ITypeSymbol? resultType)
289private static bool TryMerge(object? value1, object? value2, BinaryOperatorKind binaryOperatorKind, ITypeSymbol? type1, ITypeSymbol? type2, ITypeSymbol? resultType, [NotNullWhen(returnValue: true)] out object? result)
src\RoslynAnalyzers\Utilities\FlowAnalysis\FlowAnalysis\Framework\DataFlow\AbstractLocation.cs (8)
22/// 1. An allocation or an object creation operation (<see cref="CreateAllocationLocation(IOperation, ITypeSymbol, PointsToAnalysisContext)"/>).
26/// See <see cref="CreateFlowCaptureLocation(InterproceduralCaptureId, ITypeSymbol, ImmutableStack{IOperation})"/>
35private AbstractLocation(IOperation? creation, ImmutableStack<IOperation>? creationCallStack, AnalysisEntity? analysisEntity, ISymbol? symbol, InterproceduralCaptureId? captureId, ITypeSymbol? locationType, bool isSpecialSingleton)
48private static AbstractLocation Create(IOperation? creation, ImmutableStack<IOperation>? creationCallStack, AnalysisEntity? analysisEntity, ISymbol? symbol, InterproceduralCaptureId? captureId, ITypeSymbol? locationType)
56public static AbstractLocation CreateAllocationLocation(IOperation creation, ITypeSymbol locationType, PointsToAnalysisContext analysisContext)
58internal static AbstractLocation CreateAllocationLocation(IOperation creation, ITypeSymbol locationType, ImmutableStack<IOperation>? callStack)
66public static AbstractLocation CreateFlowCaptureLocation(InterproceduralCaptureId captureId, ITypeSymbol locationType, ImmutableStack<IOperation>? creationCallStack)
89public ITypeSymbol? LocationType { get; }
src\RoslynAnalyzers\Utilities\FlowAnalysis\FlowAnalysis\Framework\DataFlow\AnalysisEntity.cs (6)
44ITypeSymbol type,
69private AnalysisEntity(ISymbol? symbol, ImmutableArray<AbstractIndex> indices, PointsToAbstractValue location, ITypeSymbol type, AnalysisEntity? parent, AnalysisEntity? entityForInstanceLocation)
82private AnalysisEntity(InterproceduralCaptureId captureId, ITypeSymbol capturedType, PointsToAbstractValue location)
95ITypeSymbol type, PointsToAbstractValue instanceLocation, AnalysisEntity? parent, AnalysisEntity? entityForInstanceLocation)
111ITypeSymbol type,
202public ITypeSymbol Type { get; }
src\RoslynAnalyzers\Utilities\FlowAnalysis\FlowAnalysis\Framework\DataFlow\AnalysisEntityFactory.cs (7)
136ITypeSymbol? type = operation.Type;
317var type = symbol.GetMemberOrLocalOrParameterType();
347var underlyingValueTupleType = tupleType.GetUnderlyingValueTupleTypeOrThis()!;
397public bool TryCreateForArrayElementInitializer(IArrayCreationOperation arrayCreation, ImmutableArray<AbstractIndex> indices, ITypeSymbol elementType, [NotNullWhen(returnValue: true)] out AnalysisEntity? analysisEntity)
413private AnalysisEntity GetOrCreateForFlowCapture(CaptureId captureId, ITypeSymbol? type, IOperation flowCaptureOrReference, bool isLValueFlowCapture)
440ITypeSymbol type, IOperation? instance, [NotNullWhen(returnValue: true)] out AnalysisEntity? analysisEntity)
554private AnalysisEntity Create(ISymbol? symbol, ImmutableArray<AbstractIndex> indices, ITypeSymbol type, PointsToAbstractValue? instanceLocation, AnalysisEntity? parent, AnalysisEntity? entityForInstanceLocation)
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\Utilities\AbstractSpeculationAnalyzer.cs (25)
102protected abstract TConversion ClassifyConversion(SemanticModel model, TExpressionSyntax expression, ITypeSymbol targetType);
103protected abstract TConversion ClassifyConversion(SemanticModel model, ITypeSymbol originalType, ITypeSymbol targetType);
105protected abstract bool ConversionsAreCompatible(TExpressionSyntax originalExpression, ITypeSymbol originalTargetType, TExpressionSyntax newExpression, ITypeSymbol newTargetType);
106protected abstract bool IsReferenceConversion(Compilation model, ITypeSymbol sourceType, ITypeSymbol targetType);
112SemanticModel model, TForEachStatementSyntax forEach, out IMethodSymbol getEnumeratorMethod, out ITypeSymbol elementType, out ImmutableArray<ILocalSymbol> localVariables);
305private bool ImplicitConversionsAreCompatible(TExpressionSyntax originalExpression, ITypeSymbol originalTargetType, TExpressionSyntax newExpression, ITypeSymbol newTargetType)
740var previousOriginalType = this.OriginalSemanticModel.GetTypeInfo(previousOriginalNode).Type;
741var previousReplacedType = this.SpeculativeSemanticModel.GetTypeInfo(previousReplacedNode).Type;
780GetForEachSymbols(this.OriginalSemanticModel, forEachStatement, out var originalGetEnumerator, out var originalElementType, out var originalLocalVariables);
781GetForEachSymbols(this.SpeculativeSemanticModel, newForEachStatement, out var newGetEnumerator, out var newElementType, out var newLocalVariables);
826var expressionType = this.SpeculativeSemanticModel.GetTypeInfo(newForEachStatementExpression, CancellationToken).ConvertedType;
849var originalThrowExpressionType = this.OriginalSemanticModel.GetTypeInfo(originalThrowExpression).Type;
851var newThrowExpressionType = this.SpeculativeSemanticModel.GetTypeInfo(newThrowExpression).Type;
961var originalTargetType = this.OriginalSemanticModel.GetTypeInfo(originalLeft).Type;
964var newTargetType = this.SpeculativeSemanticModel.GetTypeInfo(newLeft).Type;
997var newReceiverType = newReceiver != null
1036var receiverType = semanticModel.GetTypeInfo(receiver).Type;
1196ITypeSymbol originalTargetType,
1198ITypeSymbol newTargetType,
1213var originalConvertedTypeSymbol = this.OriginalSemanticModel.GetTypeInfo(originalExpression).ConvertedType;
1219var newConvertedTypeSymbol = this.SpeculativeSemanticModel.GetTypeInfo(newExpression).ConvertedType;
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Extensions\Symbols\ITypeSymbolExtensions.cs (101)
26public static bool IsIntegralType([NotNullWhen(returnValue: true)] this ITypeSymbol? type)
29public static bool IsSignedIntegralType([NotNullWhen(returnValue: true)] this ITypeSymbol? type)
32public static bool CanAddNullCheck([NotNullWhen(returnValue: true)] this ITypeSymbol? type)
43public static ImmutableArray<INamedTypeSymbol> GetAllInterfacesIncludingThis(this ITypeSymbol type)
51public static bool IsAbstractClass([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
54public static bool IsSystemVoid([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
57public static bool IsNullable([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
60public static bool IsNonNullableValueType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
64[NotNullWhen(true)] this ITypeSymbol? symbol,
65[NotNullWhen(true)] out ITypeSymbol? underlyingType)
77public static bool IsModuleType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
80public static bool IsInterfaceType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
83public static bool IsDelegateType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
86public static bool IsFunctionPointerType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
89public static bool IsStructType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
96this ITypeSymbol type,
110public static IEnumerable<ITypeSymbol> GetBaseTypesAndThis(this ITypeSymbol? type)
112var current = type;
120public static IEnumerable<INamedTypeSymbol> GetBaseTypes(this ITypeSymbol? type)
130public static IEnumerable<ITypeSymbol> GetContainingTypesAndThis(this ITypeSymbol? type)
132var current = type;
140public static IEnumerable<INamedTypeSymbol> GetContainingTypes(this ITypeSymbol type)
153this ITypeSymbol type, ITypeSymbol baseType, bool includeInterfaces)
166this ITypeSymbol type, ITypeSymbol baseType)
174this ITypeSymbol type, ITypeSymbol baseType)
176var originalBaseType = baseType.OriginalDefinition;
184IEnumerable<ITypeSymbol> baseTypes = (baseType.TypeKind == TypeKind.Interface) ? type.AllInterfaces : type.GetBaseTypes();
191this ITypeSymbol type, ITypeSymbol baseType)
193var originalBaseType = baseType.OriginalDefinition;
213this ITypeSymbol type, ITypeSymbol interfaceType)
215var originalInterfaceType = interfaceType.OriginalDefinition;
220this ITypeSymbol type, ITypeSymbol interfaceType)
225public static bool IsAttribute(this ITypeSymbol symbol)
243public static bool IsFormattableStringOrIFormattable([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
252this ITypeSymbol typeSymbol, bool allowDelegateAndEnumConstraints = false)
280public static bool IsNumericType([NotNullWhen(returnValue: true)] this ITypeSymbol? type)
306public static Accessibility DetermineMinimalAccessibility(this ITypeSymbol typeSymbol)
309public static bool ContainsAnonymousType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
325foreach (var typeArg in type.GetAllTypeArguments())
334public static string CreateParameterName(this ITypeSymbol type, bool capitalize = false)
355private static string GetParameterName(ITypeSymbol? type)
368public static bool IsSpecialType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
399public static bool CanSupportCollectionInitializer(this ITypeSymbol typeSymbol, ISymbol within)
410public static INamedTypeSymbol? GetDelegateType(this ITypeSymbol? typeSymbol, Compilation compilation)
417var typeArgument = ((INamedTypeSymbol)typeSymbol).TypeArguments[0];
430public static IEnumerable<T> GetAccessibleMembersInBaseTypes<T>(this ITypeSymbol containingType, ISymbol within) where T : class, ISymbol
439public static ImmutableArray<T> GetAccessibleMembersInThisAndBaseTypes<T>(this ITypeSymbol? containingType, ISymbol within) where T : class, ISymbol
449public static ImmutableArray<T> GetAccessibleMembersInThisAndBaseTypes<T>(this ITypeSymbol? containingType, string memberName, ISymbol within) where T : class, ISymbol
459public static bool? AreMoreSpecificThan(this IList<ITypeSymbol> t1, IList<ITypeSymbol> t2)
494public static IEnumerable<T> SelectAccessibleMembers<T>(this IEnumerable<ITypeSymbol>? types, ISymbol within) where T : class, ISymbol
504private static IEnumerable<T> SelectAccessibleMembers<T>(this IEnumerable<ITypeSymbol>? types, string memberName, ISymbol within) where T : class, ISymbol
514private static bool? IsMoreSpecificThan(this ITypeSymbol t1, ITypeSymbol t2)
592public static bool IsOrDerivesFromExceptionType([NotNullWhen(returnValue: true)] this ITypeSymbol? type, Compilation compilation)
599foreach (var baseType in type.GetBaseTypesAndThis())
610foreach (var constraint in ((ITypeParameterSymbol)type).ConstraintTypes)
625public static bool IsEnumType([NotNullWhen(true)] this ITypeSymbol? type)
628public static bool IsEnumType([NotNullWhen(true)] this ITypeSymbol? type, [NotNullWhen(true)] out INamedTypeSymbol? enumType)
640public static bool? IsMutableValueType(this ITypeSymbol type)
642if (type.IsNullable(out var underlyingType))
721static bool IsWellKnownImmutableValueType(ITypeSymbol type)
754public static bool IsDisposable([NotNullWhen(returnValue: true)] this ITypeSymbol? type, [NotNullWhen(returnValue: true)] ITypeSymbol? iDisposableType)
759public static ITypeSymbol WithNullableAnnotationFrom(this ITypeSymbol type, ITypeSymbol symbolForNullableAnnotation)
763public static ITypeSymbol? RemoveNullableIfPresent(this ITypeSymbol? symbol)
765if (symbol.IsNullable(out var underlyingType))
773public static bool IsSpanOrReadOnlySpan([NotNullWhen(true)] this ITypeSymbol? type)
776public static bool IsSpan([NotNullWhen(true)] this ITypeSymbol? type)
792public static bool IsInlineArray([NotNullWhen(true)] this ITypeSymbol? type)
797public static ITypeSymbol? RemoveUnavailableTypeParameters(
798this ITypeSymbol? type,
806private static ITypeSymbol? RemoveUnavailableTypeParameters(
807this ITypeSymbol? type,
815public static ITypeSymbol? RemoveAnonymousTypes(
816this ITypeSymbol? type,
823public static ITypeSymbol? RemoveUnnamedErrorTypes(
824this ITypeSymbol? type,
831this ITypeSymbol? type, ArrayBuilder<ITypeParameterSymbol> result)
837this ITypeSymbol? type, ArrayBuilder<ITypeParameterSymbol> result)
843this ITypeSymbol? type, ArrayBuilder<ITypeParameterSymbol> result, bool onlyMethodTypeParameters)
852public static IList<ITypeParameterSymbol> GetReferencedTypeParameters(this ITypeSymbol? type)
860public static ITypeSymbol? SubstituteTypes<TType1, TType2>(
861this ITypeSymbol? type,
864where TType1 : ITypeSymbol
865where TType2 : ITypeSymbol
871public static ITypeSymbol? SubstituteTypes<TType1, TType2>(
872this ITypeSymbol? type,
875where TType1 : ITypeSymbol
876where TType2 : ITypeSymbol
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\Utilities\AbstractSpeculationAnalyzer.cs (25)
102protected abstract TConversion ClassifyConversion(SemanticModel model, TExpressionSyntax expression, ITypeSymbol targetType);
103protected abstract TConversion ClassifyConversion(SemanticModel model, ITypeSymbol originalType, ITypeSymbol targetType);
105protected abstract bool ConversionsAreCompatible(TExpressionSyntax originalExpression, ITypeSymbol originalTargetType, TExpressionSyntax newExpression, ITypeSymbol newTargetType);
106protected abstract bool IsReferenceConversion(Compilation model, ITypeSymbol sourceType, ITypeSymbol targetType);
112SemanticModel model, TForEachStatementSyntax forEach, out IMethodSymbol getEnumeratorMethod, out ITypeSymbol elementType, out ImmutableArray<ILocalSymbol> localVariables);
305private bool ImplicitConversionsAreCompatible(TExpressionSyntax originalExpression, ITypeSymbol originalTargetType, TExpressionSyntax newExpression, ITypeSymbol newTargetType)
740var previousOriginalType = this.OriginalSemanticModel.GetTypeInfo(previousOriginalNode).Type;
741var previousReplacedType = this.SpeculativeSemanticModel.GetTypeInfo(previousReplacedNode).Type;
780GetForEachSymbols(this.OriginalSemanticModel, forEachStatement, out var originalGetEnumerator, out var originalElementType, out var originalLocalVariables);
781GetForEachSymbols(this.SpeculativeSemanticModel, newForEachStatement, out var newGetEnumerator, out var newElementType, out var newLocalVariables);
826var expressionType = this.SpeculativeSemanticModel.GetTypeInfo(newForEachStatementExpression, CancellationToken).ConvertedType;
849var originalThrowExpressionType = this.OriginalSemanticModel.GetTypeInfo(originalThrowExpression).Type;
851var newThrowExpressionType = this.SpeculativeSemanticModel.GetTypeInfo(newThrowExpression).Type;
961var originalTargetType = this.OriginalSemanticModel.GetTypeInfo(originalLeft).Type;
964var newTargetType = this.SpeculativeSemanticModel.GetTypeInfo(newLeft).Type;
997var newReceiverType = newReceiver != null
1036var receiverType = semanticModel.GetTypeInfo(receiver).Type;
1196ITypeSymbol originalTargetType,
1198ITypeSymbol newTargetType,
1213var originalConvertedTypeSymbol = this.OriginalSemanticModel.GetTypeInfo(originalExpression).ConvertedType;
1219var newConvertedTypeSymbol = this.SpeculativeSemanticModel.GetTypeInfo(newExpression).ConvertedType;
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Extensions\Symbols\ITypeSymbolExtensions.cs (101)
26public static bool IsIntegralType([NotNullWhen(returnValue: true)] this ITypeSymbol? type)
29public static bool IsSignedIntegralType([NotNullWhen(returnValue: true)] this ITypeSymbol? type)
32public static bool CanAddNullCheck([NotNullWhen(returnValue: true)] this ITypeSymbol? type)
43public static ImmutableArray<INamedTypeSymbol> GetAllInterfacesIncludingThis(this ITypeSymbol type)
51public static bool IsAbstractClass([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
54public static bool IsSystemVoid([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
57public static bool IsNullable([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
60public static bool IsNonNullableValueType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
64[NotNullWhen(true)] this ITypeSymbol? symbol,
65[NotNullWhen(true)] out ITypeSymbol? underlyingType)
77public static bool IsModuleType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
80public static bool IsInterfaceType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
83public static bool IsDelegateType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
86public static bool IsFunctionPointerType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
89public static bool IsStructType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
96this ITypeSymbol type,
110public static IEnumerable<ITypeSymbol> GetBaseTypesAndThis(this ITypeSymbol? type)
112var current = type;
120public static IEnumerable<INamedTypeSymbol> GetBaseTypes(this ITypeSymbol? type)
130public static IEnumerable<ITypeSymbol> GetContainingTypesAndThis(this ITypeSymbol? type)
132var current = type;
140public static IEnumerable<INamedTypeSymbol> GetContainingTypes(this ITypeSymbol type)
153this ITypeSymbol type, ITypeSymbol baseType, bool includeInterfaces)
166this ITypeSymbol type, ITypeSymbol baseType)
174this ITypeSymbol type, ITypeSymbol baseType)
176var originalBaseType = baseType.OriginalDefinition;
184IEnumerable<ITypeSymbol> baseTypes = (baseType.TypeKind == TypeKind.Interface) ? type.AllInterfaces : type.GetBaseTypes();
191this ITypeSymbol type, ITypeSymbol baseType)
193var originalBaseType = baseType.OriginalDefinition;
213this ITypeSymbol type, ITypeSymbol interfaceType)
215var originalInterfaceType = interfaceType.OriginalDefinition;
220this ITypeSymbol type, ITypeSymbol interfaceType)
225public static bool IsAttribute(this ITypeSymbol symbol)
243public static bool IsFormattableStringOrIFormattable([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
252this ITypeSymbol typeSymbol, bool allowDelegateAndEnumConstraints = false)
280public static bool IsNumericType([NotNullWhen(returnValue: true)] this ITypeSymbol? type)
306public static Accessibility DetermineMinimalAccessibility(this ITypeSymbol typeSymbol)
309public static bool ContainsAnonymousType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
325foreach (var typeArg in type.GetAllTypeArguments())
334public static string CreateParameterName(this ITypeSymbol type, bool capitalize = false)
355private static string GetParameterName(ITypeSymbol? type)
368public static bool IsSpecialType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
399public static bool CanSupportCollectionInitializer(this ITypeSymbol typeSymbol, ISymbol within)
410public static INamedTypeSymbol? GetDelegateType(this ITypeSymbol? typeSymbol, Compilation compilation)
417var typeArgument = ((INamedTypeSymbol)typeSymbol).TypeArguments[0];
430public static IEnumerable<T> GetAccessibleMembersInBaseTypes<T>(this ITypeSymbol containingType, ISymbol within) where T : class, ISymbol
439public static ImmutableArray<T> GetAccessibleMembersInThisAndBaseTypes<T>(this ITypeSymbol? containingType, ISymbol within) where T : class, ISymbol
449public static ImmutableArray<T> GetAccessibleMembersInThisAndBaseTypes<T>(this ITypeSymbol? containingType, string memberName, ISymbol within) where T : class, ISymbol
459public static bool? AreMoreSpecificThan(this IList<ITypeSymbol> t1, IList<ITypeSymbol> t2)
494public static IEnumerable<T> SelectAccessibleMembers<T>(this IEnumerable<ITypeSymbol>? types, ISymbol within) where T : class, ISymbol
504private static IEnumerable<T> SelectAccessibleMembers<T>(this IEnumerable<ITypeSymbol>? types, string memberName, ISymbol within) where T : class, ISymbol
514private static bool? IsMoreSpecificThan(this ITypeSymbol t1, ITypeSymbol t2)
592public static bool IsOrDerivesFromExceptionType([NotNullWhen(returnValue: true)] this ITypeSymbol? type, Compilation compilation)
599foreach (var baseType in type.GetBaseTypesAndThis())
610foreach (var constraint in ((ITypeParameterSymbol)type).ConstraintTypes)
625public static bool IsEnumType([NotNullWhen(true)] this ITypeSymbol? type)
628public static bool IsEnumType([NotNullWhen(true)] this ITypeSymbol? type, [NotNullWhen(true)] out INamedTypeSymbol? enumType)
640public static bool? IsMutableValueType(this ITypeSymbol type)
642if (type.IsNullable(out var underlyingType))
721static bool IsWellKnownImmutableValueType(ITypeSymbol type)
754public static bool IsDisposable([NotNullWhen(returnValue: true)] this ITypeSymbol? type, [NotNullWhen(returnValue: true)] ITypeSymbol? iDisposableType)
759public static ITypeSymbol WithNullableAnnotationFrom(this ITypeSymbol type, ITypeSymbol symbolForNullableAnnotation)
763public static ITypeSymbol? RemoveNullableIfPresent(this ITypeSymbol? symbol)
765if (symbol.IsNullable(out var underlyingType))
773public static bool IsSpanOrReadOnlySpan([NotNullWhen(true)] this ITypeSymbol? type)
776public static bool IsSpan([NotNullWhen(true)] this ITypeSymbol? type)
792public static bool IsInlineArray([NotNullWhen(true)] this ITypeSymbol? type)
797public static ITypeSymbol? RemoveUnavailableTypeParameters(
798this ITypeSymbol? type,
806private static ITypeSymbol? RemoveUnavailableTypeParameters(
807this ITypeSymbol? type,
815public static ITypeSymbol? RemoveAnonymousTypes(
816this ITypeSymbol? type,
823public static ITypeSymbol? RemoveUnnamedErrorTypes(
824this ITypeSymbol? type,
831this ITypeSymbol? type, ArrayBuilder<ITypeParameterSymbol> result)
837this ITypeSymbol? type, ArrayBuilder<ITypeParameterSymbol> result)
843this ITypeSymbol? type, ArrayBuilder<ITypeParameterSymbol> result, bool onlyMethodTypeParameters)
852public static IList<ITypeParameterSymbol> GetReferencedTypeParameters(this ITypeSymbol? type)
860public static ITypeSymbol? SubstituteTypes<TType1, TType2>(
861this ITypeSymbol? type,
864where TType1 : ITypeSymbol
865where TType2 : ITypeSymbol
871public static ITypeSymbol? SubstituteTypes<TType1, TType2>(
872this ITypeSymbol? type,
875where TType1 : ITypeSymbol
876where TType2 : ITypeSymbol
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\Core\CodeGeneration\CodeGenerationSymbolFactory.cs (18)
30DeclarationModifiers modifiers, ITypeSymbol type,
47ITypeSymbol type,
79ITypeSymbol type, RefKind refKind, ImmutableArray<IPropertySymbol> explicitInterfaceImplementations, string name,
106ITypeSymbol type, string name,
152ITypeSymbol? returnType,
174ITypeSymbol? returnType,
195ITypeSymbol returnType,
220ITypeSymbol toType,
248ITypeSymbol toType,
264public static IParameterSymbol CreateParameterSymbol(ITypeSymbol type, string name)
267public static IParameterSymbol CreateParameterSymbol(RefKind refKind, ITypeSymbol type, string name)
277ImmutableArray<AttributeData> attributes, RefKind refKind, bool isParams, ITypeSymbol type, string name, bool isOptional = false, bool hasDefaultValue = false, object? defaultValue = null)
290ITypeSymbol? type = null,
331ImmutableArray<ITypeSymbol> constraintTypes,
347public static IPointerTypeSymbol CreatePointerTypeSymbol(ITypeSymbol pointedAtType)
353public static IArrayTypeSymbol CreateArrayTypeSymbol(ITypeSymbol elementType, int rank = 1, NullableAnnotation nullableAnnotation = NullableAnnotation.None)
463ITypeSymbol returnType,
520ITypeSymbol? returnType = null,
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\Core\CodeGeneration\Symbols\CodeGenerationArrayTypeSymbol.cs (2)
10internal sealed class CodeGenerationArrayTypeSymbol(ITypeSymbol elementType, int rank, NullableAnnotation nullableAnnotation) : CodeGenerationTypeSymbol(null, null, default, Accessibility.NotApplicable, default, string.Empty, SpecialType.None, nullableAnnotation), IArrayTypeSymbol
12public ITypeSymbol ElementType { get; } = elementType;
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\Core\CodeGeneration\Symbols\CodeGenerationConversionSymbol.cs (1)
15ITypeSymbol toType,
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\Core\CodeGeneration\Symbols\CodeGenerationOperatorSymbol.cs (1)
15ITypeSymbol returnType,
src\Analyzers\Core\Analyzers\RemoveUnusedParametersAndValues\AbstractRemoveUnusedParametersAndValuesDiagnosticAnalyzer.SymbolStartAnalyzer.cs (1)
292ITypeSymbol containingType,
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\Utilities\AbstractSpeculationAnalyzer.cs (25)
102protected abstract TConversion ClassifyConversion(SemanticModel model, TExpressionSyntax expression, ITypeSymbol targetType);
103protected abstract TConversion ClassifyConversion(SemanticModel model, ITypeSymbol originalType, ITypeSymbol targetType);
105protected abstract bool ConversionsAreCompatible(TExpressionSyntax originalExpression, ITypeSymbol originalTargetType, TExpressionSyntax newExpression, ITypeSymbol newTargetType);
106protected abstract bool IsReferenceConversion(Compilation model, ITypeSymbol sourceType, ITypeSymbol targetType);
112SemanticModel model, TForEachStatementSyntax forEach, out IMethodSymbol getEnumeratorMethod, out ITypeSymbol elementType, out ImmutableArray<ILocalSymbol> localVariables);
305private bool ImplicitConversionsAreCompatible(TExpressionSyntax originalExpression, ITypeSymbol originalTargetType, TExpressionSyntax newExpression, ITypeSymbol newTargetType)
740var previousOriginalType = this.OriginalSemanticModel.GetTypeInfo(previousOriginalNode).Type;
741var previousReplacedType = this.SpeculativeSemanticModel.GetTypeInfo(previousReplacedNode).Type;
780GetForEachSymbols(this.OriginalSemanticModel, forEachStatement, out var originalGetEnumerator, out var originalElementType, out var originalLocalVariables);
781GetForEachSymbols(this.SpeculativeSemanticModel, newForEachStatement, out var newGetEnumerator, out var newElementType, out var newLocalVariables);
826var expressionType = this.SpeculativeSemanticModel.GetTypeInfo(newForEachStatementExpression, CancellationToken).ConvertedType;
849var originalThrowExpressionType = this.OriginalSemanticModel.GetTypeInfo(originalThrowExpression).Type;
851var newThrowExpressionType = this.SpeculativeSemanticModel.GetTypeInfo(newThrowExpression).Type;
961var originalTargetType = this.OriginalSemanticModel.GetTypeInfo(originalLeft).Type;
964var newTargetType = this.SpeculativeSemanticModel.GetTypeInfo(newLeft).Type;
997var newReceiverType = newReceiver != null
1036var receiverType = semanticModel.GetTypeInfo(receiver).Type;
1196ITypeSymbol originalTargetType,
1198ITypeSymbol newTargetType,
1213var originalConvertedTypeSymbol = this.OriginalSemanticModel.GetTypeInfo(originalExpression).ConvertedType;
1219var newConvertedTypeSymbol = this.SpeculativeSemanticModel.GetTypeInfo(newExpression).ConvertedType;
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Extensions\Symbols\ITypeSymbolExtensions.cs (101)
26public static bool IsIntegralType([NotNullWhen(returnValue: true)] this ITypeSymbol? type)
29public static bool IsSignedIntegralType([NotNullWhen(returnValue: true)] this ITypeSymbol? type)
32public static bool CanAddNullCheck([NotNullWhen(returnValue: true)] this ITypeSymbol? type)
43public static ImmutableArray<INamedTypeSymbol> GetAllInterfacesIncludingThis(this ITypeSymbol type)
51public static bool IsAbstractClass([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
54public static bool IsSystemVoid([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
57public static bool IsNullable([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
60public static bool IsNonNullableValueType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
64[NotNullWhen(true)] this ITypeSymbol? symbol,
65[NotNullWhen(true)] out ITypeSymbol? underlyingType)
77public static bool IsModuleType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
80public static bool IsInterfaceType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
83public static bool IsDelegateType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
86public static bool IsFunctionPointerType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
89public static bool IsStructType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
96this ITypeSymbol type,
110public static IEnumerable<ITypeSymbol> GetBaseTypesAndThis(this ITypeSymbol? type)
112var current = type;
120public static IEnumerable<INamedTypeSymbol> GetBaseTypes(this ITypeSymbol? type)
130public static IEnumerable<ITypeSymbol> GetContainingTypesAndThis(this ITypeSymbol? type)
132var current = type;
140public static IEnumerable<INamedTypeSymbol> GetContainingTypes(this ITypeSymbol type)
153this ITypeSymbol type, ITypeSymbol baseType, bool includeInterfaces)
166this ITypeSymbol type, ITypeSymbol baseType)
174this ITypeSymbol type, ITypeSymbol baseType)
176var originalBaseType = baseType.OriginalDefinition;
184IEnumerable<ITypeSymbol> baseTypes = (baseType.TypeKind == TypeKind.Interface) ? type.AllInterfaces : type.GetBaseTypes();
191this ITypeSymbol type, ITypeSymbol baseType)
193var originalBaseType = baseType.OriginalDefinition;
213this ITypeSymbol type, ITypeSymbol interfaceType)
215var originalInterfaceType = interfaceType.OriginalDefinition;
220this ITypeSymbol type, ITypeSymbol interfaceType)
225public static bool IsAttribute(this ITypeSymbol symbol)
243public static bool IsFormattableStringOrIFormattable([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
252this ITypeSymbol typeSymbol, bool allowDelegateAndEnumConstraints = false)
280public static bool IsNumericType([NotNullWhen(returnValue: true)] this ITypeSymbol? type)
306public static Accessibility DetermineMinimalAccessibility(this ITypeSymbol typeSymbol)
309public static bool ContainsAnonymousType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
325foreach (var typeArg in type.GetAllTypeArguments())
334public static string CreateParameterName(this ITypeSymbol type, bool capitalize = false)
355private static string GetParameterName(ITypeSymbol? type)
368public static bool IsSpecialType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
399public static bool CanSupportCollectionInitializer(this ITypeSymbol typeSymbol, ISymbol within)
410public static INamedTypeSymbol? GetDelegateType(this ITypeSymbol? typeSymbol, Compilation compilation)
417var typeArgument = ((INamedTypeSymbol)typeSymbol).TypeArguments[0];
430public static IEnumerable<T> GetAccessibleMembersInBaseTypes<T>(this ITypeSymbol containingType, ISymbol within) where T : class, ISymbol
439public static ImmutableArray<T> GetAccessibleMembersInThisAndBaseTypes<T>(this ITypeSymbol? containingType, ISymbol within) where T : class, ISymbol
449public static ImmutableArray<T> GetAccessibleMembersInThisAndBaseTypes<T>(this ITypeSymbol? containingType, string memberName, ISymbol within) where T : class, ISymbol
459public static bool? AreMoreSpecificThan(this IList<ITypeSymbol> t1, IList<ITypeSymbol> t2)
494public static IEnumerable<T> SelectAccessibleMembers<T>(this IEnumerable<ITypeSymbol>? types, ISymbol within) where T : class, ISymbol
504private static IEnumerable<T> SelectAccessibleMembers<T>(this IEnumerable<ITypeSymbol>? types, string memberName, ISymbol within) where T : class, ISymbol
514private static bool? IsMoreSpecificThan(this ITypeSymbol t1, ITypeSymbol t2)
592public static bool IsOrDerivesFromExceptionType([NotNullWhen(returnValue: true)] this ITypeSymbol? type, Compilation compilation)
599foreach (var baseType in type.GetBaseTypesAndThis())
610foreach (var constraint in ((ITypeParameterSymbol)type).ConstraintTypes)
625public static bool IsEnumType([NotNullWhen(true)] this ITypeSymbol? type)
628public static bool IsEnumType([NotNullWhen(true)] this ITypeSymbol? type, [NotNullWhen(true)] out INamedTypeSymbol? enumType)
640public static bool? IsMutableValueType(this ITypeSymbol type)
642if (type.IsNullable(out var underlyingType))
721static bool IsWellKnownImmutableValueType(ITypeSymbol type)
754public static bool IsDisposable([NotNullWhen(returnValue: true)] this ITypeSymbol? type, [NotNullWhen(returnValue: true)] ITypeSymbol? iDisposableType)
759public static ITypeSymbol WithNullableAnnotationFrom(this ITypeSymbol type, ITypeSymbol symbolForNullableAnnotation)
763public static ITypeSymbol? RemoveNullableIfPresent(this ITypeSymbol? symbol)
765if (symbol.IsNullable(out var underlyingType))
773public static bool IsSpanOrReadOnlySpan([NotNullWhen(true)] this ITypeSymbol? type)
776public static bool IsSpan([NotNullWhen(true)] this ITypeSymbol? type)
792public static bool IsInlineArray([NotNullWhen(true)] this ITypeSymbol? type)
797public static ITypeSymbol? RemoveUnavailableTypeParameters(
798this ITypeSymbol? type,
806private static ITypeSymbol? RemoveUnavailableTypeParameters(
807this ITypeSymbol? type,
815public static ITypeSymbol? RemoveAnonymousTypes(
816this ITypeSymbol? type,
823public static ITypeSymbol? RemoveUnnamedErrorTypes(
824this ITypeSymbol? type,
831this ITypeSymbol? type, ArrayBuilder<ITypeParameterSymbol> result)
837this ITypeSymbol? type, ArrayBuilder<ITypeParameterSymbol> result)
843this ITypeSymbol? type, ArrayBuilder<ITypeParameterSymbol> result, bool onlyMethodTypeParameters)
852public static IList<ITypeParameterSymbol> GetReferencedTypeParameters(this ITypeSymbol? type)
860public static ITypeSymbol? SubstituteTypes<TType1, TType2>(
861this ITypeSymbol? type,
864where TType1 : ITypeSymbol
865where TType2 : ITypeSymbol
871public static ITypeSymbol? SubstituteTypes<TType1, TType2>(
872this ITypeSymbol? type,
875where TType1 : ITypeSymbol
876where TType2 : ITypeSymbol
src\Analyzers\Core\CodeFixes\AddExplicitCast\AbstractAddExplicitCastCodeFixProvider.cs (11)
31protected abstract TExpressionSyntax Cast(TExpressionSyntax expression, ITypeSymbol type);
49protected ImmutableArray<(TExpressionSyntax node, ITypeSymbol type)> GetPotentialTargetTypes(
53using var _ = ArrayBuilder<(TExpressionSyntax node, ITypeSymbol type)>.GetInstance(out var candidates);
64ArrayBuilder<(TExpressionSyntax node, ITypeSymbol type)> candidates,
120ITypeSymbol conversionType,
143var castType = semanticModel.GetTypeInfo(castTypeNode, cancellationToken).Type;
161protected virtual (SyntaxNode finalTarget, SyntaxNode finalReplacement) Cast(SemanticModel semanticModel, TExpressionSyntax targetNode, ITypeSymbol conversionType)
164private static string GetSubItemName(SemanticModel semanticModel, int position, ITypeSymbol conversionType)
171private static ImmutableArray<(TExpressionSyntax, ITypeSymbol)> FilterValidPotentialConversionTypes(
174ArrayBuilder<(TExpressionSyntax node, ITypeSymbol type)> candidates)
179using var _ = ArrayBuilder<(TExpressionSyntax, ITypeSymbol)>.GetInstance(candidates.Count, out var validPotentialConversionTypes);
src\Analyzers\Core\CodeFixes\AddParameter\AbstractAddParameterCodeFixProvider.cs (4)
47protected abstract ITypeSymbol GetArgumentType(SyntaxNode argumentNode, SemanticModel semanticModel, CancellationToken cancellationToken);
402private async Task<(ITypeSymbol, RefKind)> GetArgumentTypeAndRefKindAsync(Document invocationDocument, TArgumentSyntax argument, CancellationToken cancellationToken)
406var argumentType = GetArgumentType(argument, semanticModel, cancellationToken);
537Compilation compilation, TypeInfo argumentTypeInfo, ITypeSymbol parameterType,
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\Core\CodeGeneration\CodeGenerationSymbolFactory.cs (18)
30DeclarationModifiers modifiers, ITypeSymbol type,
47ITypeSymbol type,
79ITypeSymbol type, RefKind refKind, ImmutableArray<IPropertySymbol> explicitInterfaceImplementations, string name,
106ITypeSymbol type, string name,
152ITypeSymbol? returnType,
174ITypeSymbol? returnType,
195ITypeSymbol returnType,
220ITypeSymbol toType,
248ITypeSymbol toType,
264public static IParameterSymbol CreateParameterSymbol(ITypeSymbol type, string name)
267public static IParameterSymbol CreateParameterSymbol(RefKind refKind, ITypeSymbol type, string name)
277ImmutableArray<AttributeData> attributes, RefKind refKind, bool isParams, ITypeSymbol type, string name, bool isOptional = false, bool hasDefaultValue = false, object? defaultValue = null)
290ITypeSymbol? type = null,
331ImmutableArray<ITypeSymbol> constraintTypes,
347public static IPointerTypeSymbol CreatePointerTypeSymbol(ITypeSymbol pointedAtType)
353public static IArrayTypeSymbol CreateArrayTypeSymbol(ITypeSymbol elementType, int rank = 1, NullableAnnotation nullableAnnotation = NullableAnnotation.None)
463ITypeSymbol returnType,
520ITypeSymbol? returnType = null,
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\Core\CodeGeneration\Symbols\CodeGenerationArrayTypeSymbol.cs (2)
10internal sealed class CodeGenerationArrayTypeSymbol(ITypeSymbol elementType, int rank, NullableAnnotation nullableAnnotation) : CodeGenerationTypeSymbol(null, null, default, Accessibility.NotApplicable, default, string.Empty, SpecialType.None, nullableAnnotation), IArrayTypeSymbol
12public ITypeSymbol ElementType { get; } = elementType;
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\Core\CodeGeneration\Symbols\CodeGenerationConversionSymbol.cs (1)
15ITypeSymbol toType,
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\Core\CodeGeneration\Symbols\CodeGenerationOperatorSymbol.cs (1)
15ITypeSymbol returnType,
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\CSharp\Extensions\ExpressionSyntaxExtensions.cs (24)
906public static ITypeSymbol? GetTargetType(
936bool HasType(ExpressionSyntax expression, [NotNullWhen(true)] out ITypeSymbol? type)
942ITypeSymbol? GetTargetTypeForArgument(ArgumentSyntax argument)
946var tupleType = tupleExpression.GetTargetType(semanticModel, cancellationToken);
961ITypeSymbol? GetTargetTypeForAttributeArgument(AttributeArgumentSyntax argument)
964ITypeSymbol? GetTargetTypeForArrowExpression(ArrowExpressionClauseSyntax arrowExpression)
971ITypeSymbol? GetTargetTypeForReturnStatement(ReturnStatementSyntax returnStatement)
985ITypeSymbol? GetTargetTypeForEqualsValueClause(EqualsValueClauseSyntax equalsValue)
995ITypeSymbol? GetTargetTypedForCastExpression(CastExpressionSyntax castExpression)
998ITypeSymbol? GetTargetTypeForConditionalExpression(ConditionalExpressionSyntax conditionalExpression, ExpressionSyntax expression)
1001return HasType(conditionalExpression.WhenFalse, out var falseType) ? falseType : conditionalExpression.GetTargetType(semanticModel, cancellationToken);
1003return HasType(conditionalExpression.WhenTrue, out var trueType) ? trueType : conditionalExpression.GetTargetType(semanticModel, cancellationToken);
1008ITypeSymbol? GetTargetTypeForLambdaExpression(LambdaExpressionSyntax lambda, ExpressionSyntax expression)
1012ITypeSymbol? GetTargetTypeForSwitchExpressionArm(SwitchExpressionArmSyntax switchExpressionArm)
1019if (arm != switchExpressionArm && HasType(arm.Expression, out var armType))
1027ITypeSymbol? GetTargetTypeForCollectionElement(CollectionElementSyntax collectionElement)
1035var collectionTargetType = collectionExpression.GetTargetType(semanticModel, cancellationToken);
1055ITypeSymbol? GetTargetTypeForInitializerExpression(InitializerExpressionSyntax initializerExpression, ExpressionSyntax expression)
1059return HasType(arrayCreation.Type, out var elementType) ? elementType : null;
1066if (sibling != expression && HasType(sibling, out var siblingType))
1084ITypeSymbol? GetTargetTypeForAssignmentExpression(AssignmentExpressionSyntax assignmentExpression, ExpressionSyntax expression)
1086return expression == assignmentExpression.Right && HasType(assignmentExpression.Left, out var leftType) ? leftType : null;
1089ITypeSymbol? GetTargetTypeForBinaryExpression(BinaryExpressionSyntax binaryExpression, ExpressionSyntax expression)
1091return binaryExpression.Kind() == SyntaxKind.CoalesceExpression && binaryExpression.Right == expression && HasType(binaryExpression.Left, out var leftType) ? leftType : null;
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\CSharp\Simplification\Simplifiers\CastSimplifier.cs (34)
129var castedType = semanticModel.GetTypeInfo(castExpression.Type, cancellationToken).Type;
164var castedType = semanticModel.GetTypeInfo(castExpression.Type, cancellationToken).Type;
168var parentCastType = semanticModel.GetTypeInfo(parentCast.Type, cancellationToken).Type;
315var originalConvertedType = originalSemanticModel.GetTypeInfo(castNode.WalkUpParentheses(), cancellationToken).ConvertedType;
507var castedExpressionType = originalSemanticModel.GetTypeInfo(castedExpressionNode, cancellationToken).Type;
508var isType = originalSemanticModel.GetTypeInfo(isExpression.Right, cancellationToken).Type;
544var targetType = castNode.GetTargetType(originalSemanticModel, cancellationToken);
619ITypeSymbol originalConvertedType,
623var castedType = originalSemanticModel.GetTypeInfo(castNode, cancellationToken).Type;
698var castType = semanticModel.GetTypeInfo(castNode, cancellationToken).Type;
818var originalConvertedType = originalConversionOperation.Type;
819var rewrittenBitwiseNotConversionType = rewrittenBitwiseNotConversionOperation.Type;
832private static bool IsSignedIntegralOrIntPtrType(ITypeSymbol? type)
954var castType = originalSemanticModel.GetTypeInfo(castExpression, cancellationToken).Type;
988var otherSideType = originalSemanticModel.GetTypeInfo(otherSide, cancellationToken).Type;
989var thisSideRewrittenType = rewrittenSemanticModel.GetTypeInfo(rewrittenExpression, cancellationToken).Type;
1001var rewrittenConditionalConvertedType = rewrittenSemanticModel.GetTypeInfo(rewrittenConditionalOrSwitchExpression, cancellationToken).ConvertedType;
1036private static bool IsNullOrErrorType([NotNullWhen(false)] ITypeSymbol? type)
1159var castSideType = semanticModel.GetTypeInfo(castSide, cancellationToken).Type;
1160var castedExpressionType = semanticModel.GetTypeInfo(castExpression.Expression, cancellationToken).Type;
1162if (castSideType.IsNullable(out var underlyingType) && Equals(underlyingType, castedExpressionType))
1164var otherSideType = semanticModel.GetTypeInfo(otherSide, cancellationToken).Type;
1182var castType = semanticModel.GetTypeInfo(castNode, cancellationToken).Type;
1183var castedExpressionType = semanticModel.GetTypeInfo(castedExpressionNode, cancellationToken).Type;
1240private static bool IsFloatingPointType(ITypeSymbol? type)
1410var rewrittenType = rewrittenSemanticModel.GetTypeInfo(rewrittenExpression, cancellationToken).Type;
1525private static bool IsIntrinsicOrEnum(ITypeSymbol rewrittenType)
1533ITypeSymbol rewrittenType,
1572var originalMemberType = originalMemberSymbol.GetMemberType();
1573var rewrittenMemberType = rewrittenMemberSymbol.GetMemberType();
1623private static (ITypeSymbol? rewrittenConvertedType, Conversion rewrittenConversion) GetRewrittenInfo(
1626Conversion originalConversion, ITypeSymbol originalConvertedType,
1637var convertedType = originalConversion.IsIdentity ? originalConvertedType : originalSemanticModel.Compilation.ObjectType;
1641var rewrittenConvertedType = rewrittenSemanticModel.GetTypeInfo(rewrittenExpression, cancellationToken).ConvertedType;
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\CSharp\Utilities\SpeculationAnalyzer.cs (18)
267var originalParamType = this.OriginalSemanticModel.GetDeclaredSymbol(originalParam).Type;
268var replacedParamType = this.SpeculativeSemanticModel.GetDeclaredSymbol(replacedParam).Type;
386var originalExpressionType = originalExpressionTypeInfo.Type;
387var newExpressionType = newExpressionTypeInfo.Type;
435var originalCaseType = this.OriginalSemanticModel.GetTypeInfo(previousOriginalNode, this.CancellationToken).Type;
436var newCaseType = this.SpeculativeSemanticModel.GetTypeInfo(previousReplacedNode, this.CancellationToken).Type;
561var originalExpressionType = this.OriginalSemanticModel.GetTypeInfo(originalAnonymousObjectMemberDeclarator.Expression, this.CancellationToken).Type;
562var newExpressionType = this.SpeculativeSemanticModel.GetTypeInfo(replacedAnonymousObjectMemberDeclarator.Expression, this.CancellationToken).Type;
702var originalConvertedType = this.OriginalSemanticModel.GetTypeInfo(originalIsOrAsExpression.Right).Type;
703var newConvertedType = this.SpeculativeSemanticModel.GetTypeInfo(newIsOrAsExpression.Right).Type;
841protected override bool ConversionsAreCompatible(ExpressionSyntax originalExpression, ITypeSymbol originalTargetType, ExpressionSyntax newExpression, ITypeSymbol newTargetType)
889out ITypeSymbol elementType,
931protected override bool IsReferenceConversion(Compilation compilation, ITypeSymbol sourceType, ITypeSymbol targetType)
934protected override Conversion ClassifyConversion(SemanticModel model, ExpressionSyntax expression, ITypeSymbol targetType)
937protected override Conversion ClassifyConversion(SemanticModel model, ITypeSymbol originalType, ITypeSymbol targetType)
src\Analyzers\CSharp\CodeFixes\GenerateMethod\GenerateDeconstructMethodCodeFixProvider.cs (1)
57ITypeSymbol? type;
src\Analyzers\CSharp\CodeFixes\Iterator\CSharpAddYieldCodeFixProvider.cs (10)
54if (!TryGetMethodReturnType(node, model, cancellationToken, out var methodReturnType))
59if (!TryGetExpressionType(model, returnStatement.Expression, out var returnExpressionType))
89SemanticModel model, ExpressionSyntax? expression, [NotNullWhen(true)] out ITypeSymbol? returnExpressionType)
104[NotNullWhen(true)] out ITypeSymbol? methodReturnType)
117private static bool IsCorrectTypeForYieldReturn(ITypeSymbol typeArgument, ITypeSymbol returnExpressionType, ITypeSymbol methodReturnType, SemanticModel model)
151private static bool CanConvertTypes(ITypeSymbol typeArgument, ITypeSymbol returnExpressionType, SemanticModel model)
190private static bool IsCorrectTypeForYieldReturn(ITypeSymbol methodReturnType, SemanticModel model)
src\Analyzers\CSharp\CodeFixes\UseImplicitOrExplicitType\UseExplicitTypeCodeFixProvider.cs (11)
95var tupleTypeSymbol = GetConvertedType(semanticModel, typeSyntax.Parent, cancellationToken);
107var typeSymbol = GetConvertedType(semanticModel, typeSyntax, cancellationToken);
142var typeSymbol = GetConvertedType(semanticModel, typeSyntax, cancellationToken);
154private static ITypeSymbol AdjustNullabilityOfTypeSymbol(
157ITypeSymbol typeSymbol,
178ITypeSymbol typeSymbol,
190var type = elements[i].Type;
197var symbolType = localSymbol.GetSymbolType() ?? type;
228private static TypeSyntax GenerateTypeDeclaration(TypeSyntax typeSyntax, ITypeSymbol newTypeSymbol)
240private static ITypeSymbol GetConvertedType(SemanticModel semanticModel, SyntaxNode typeSyntax, CancellationToken cancellationToken)
242var typeSymbol = semanticModel.GetTypeInfo(typeSyntax, cancellationToken).ConvertedType;
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\CSharp\CodeGeneration\ExpressionGenerator.cs (10)
34return typedConstant.Value is ITypeSymbol typeSymbol
54ITypeSymbol? type,
63if (type.IsNullable(out var underlyingType))
75internal static ExpressionSyntax GenerateNonEnumValueExpression(ITypeSymbol? type, object? value, bool canUseFieldReference)
118private static string DetermineSuffix(ITypeSymbol? type, object value)
172private static ExpressionSyntax GenerateDoubleLiteralExpression(ITypeSymbol? type, double value, bool canUseFieldReference)
201private static ExpressionSyntax GenerateSingleLiteralExpression(ITypeSymbol? type, float value, bool canUseFieldReference)
231ITypeSymbol? type, T value, IEnumerable<KeyValuePair<T, string>> constants,
242ITypeSymbol? type, T value, IEnumerable<KeyValuePair<T, string>> constants,
278private static ExpressionSyntax? GenerateFieldReference<T>(ITypeSymbol? type, T value, IEnumerable<KeyValuePair<T, string>> constants)
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\CSharp\LanguageServices\CSharpTypeInferenceService.TypeInferrer.cs (36)
35protected override bool IsUnusableType(ITypeSymbol otherSideType)
616private static IMethodSymbol Instantiate(IMethodSymbol method, IList<ITypeSymbol> invocationTypes)
640IDictionary<ITypeParameterSymbol, ITypeSymbol> bestMap = null;
641foreach (var type in invocationTypes)
662private static Dictionary<ITypeParameterSymbol, ITypeSymbol> DetermineTypeParameterMapping(ITypeSymbol inferredType, ITypeSymbol returnType)
664var result = new Dictionary<ITypeParameterSymbol, ITypeSymbol>();
669private static void DetermineTypeParameterMapping(ITypeSymbol inferredType, ITypeSymbol returnType, Dictionary<ITypeParameterSymbol, ITypeSymbol> result)
1122return leftTypes.Select(x => x.InferredType.IsNullable(out var underlying)
1134static ITypeSymbol MakeNullable(ITypeSymbol symbol, Compilation compilation)
1448var type = this.SemanticModel.GetTypeInfo(recursivePattern).ConvertedType;
1567var elementTypesBuilder = ArrayBuilder<ITypeSymbol>.GetInstance(subPatternCount);
1592private static ImmutableArray<NullableAnnotation> GetNullableAnnotations(ImmutableArray<ITypeSymbol> elementTypes)
1763var typeArg = delegateType?.TypeArguments.Length > 0
1781private ITypeSymbol InferTypeForFirstParameterOfLambda(
1796private ITypeSymbol InferTypeForFirstParameterOfParenthesizedLambda(
1805private ITypeSymbol InferTypeForFirstParameterOfSimpleLambda(
1812private ITypeSymbol InferTypeForFirstParameterOfLambda(
1819private ITypeSymbol InferTypeForFirstParameterOfLambda(
1837var type = InferTypeForFirstParameterOfLambda(parameterName, child.AsNode());
1990var memberType = memberSymbol.GetMemberType();
2002private ITypeSymbol UnwrapTaskLike(ITypeSymbol type, bool isAsync)
2043var type = symbol.GetMemberType();
2182var type = symbol.GetSymbolType();
2271var tupleType = GetTupleType(tupleExpression);
2280private ITypeSymbol GetTupleType(
2294out ImmutableArray<ITypeSymbol> elementTypes,
2300using var _1 = ArrayBuilder<ITypeSymbol>.GetInstance(out var elementTypesBuilder);
2338ArrayBuilder<ITypeSymbol> elementTypesBuilder,
2360ArrayBuilder<ITypeSymbol> elementTypesBuilder,
2363var tupleType = GetTupleType(tuple);
Completion\CompletionProviders\PropertySubPatternCompletionProvider.cs (7)
58var propertyPatternType = semanticModel.GetTypeInfo((PatternSyntax)propertyPatternClause.Parent!, cancellationToken).ConvertedType;
62var type = GetMemberAccessType(propertyPatternType, memberAccess, document, semanticModel, position);
98static ITypeSymbol? GetMemberAccessType(ITypeSymbol? type, ExpressionSyntax? expression, Document document, SemanticModel semanticModel, int position)
117static ITypeSymbol? GetMemberType(ITypeSymbol? type, string name, Document document, SemanticModel semanticModel, int position)
134static ImmutableArray<ISymbol> GetCandidatePropertiesAndFields(Document document, SemanticModel semanticModel, int position, ITypeSymbol? type)
src\Analyzers\CSharp\CodeFixes\GenerateMethod\GenerateDeconstructMethodCodeFixProvider.cs (1)
57ITypeSymbol? type;
src\Analyzers\CSharp\CodeFixes\Iterator\CSharpAddYieldCodeFixProvider.cs (10)
54if (!TryGetMethodReturnType(node, model, cancellationToken, out var methodReturnType))
59if (!TryGetExpressionType(model, returnStatement.Expression, out var returnExpressionType))
89SemanticModel model, ExpressionSyntax? expression, [NotNullWhen(true)] out ITypeSymbol? returnExpressionType)
104[NotNullWhen(true)] out ITypeSymbol? methodReturnType)
117private static bool IsCorrectTypeForYieldReturn(ITypeSymbol typeArgument, ITypeSymbol returnExpressionType, ITypeSymbol methodReturnType, SemanticModel model)
151private static bool CanConvertTypes(ITypeSymbol typeArgument, ITypeSymbol returnExpressionType, SemanticModel model)
190private static bool IsCorrectTypeForYieldReturn(ITypeSymbol methodReturnType, SemanticModel model)
src\Analyzers\CSharp\CodeFixes\UseImplicitOrExplicitType\UseExplicitTypeCodeFixProvider.cs (11)
95var tupleTypeSymbol = GetConvertedType(semanticModel, typeSyntax.Parent, cancellationToken);
107var typeSymbol = GetConvertedType(semanticModel, typeSyntax, cancellationToken);
142var typeSymbol = GetConvertedType(semanticModel, typeSyntax, cancellationToken);
154private static ITypeSymbol AdjustNullabilityOfTypeSymbol(
157ITypeSymbol typeSymbol,
178ITypeSymbol typeSymbol,
190var type = elements[i].Type;
197var symbolType = localSymbol.GetSymbolType() ?? type;
228private static TypeSyntax GenerateTypeDeclaration(TypeSyntax typeSyntax, ITypeSymbol newTypeSymbol)
240private static ITypeSymbol GetConvertedType(SemanticModel semanticModel, SyntaxNode typeSyntax, CancellationToken cancellationToken)
242var typeSymbol = semanticModel.GetTypeInfo(typeSyntax, cancellationToken).ConvertedType;
Recommendations\CSharpRecommendationServiceRunner.cs (14)
51public override bool TryGetExplicitTypeOfLambdaParameter(SyntaxNode lambdaSyntax, int ordinalInLambda, [NotNullWhen(true)] out ITypeSymbol? explicitLambdaParameterType)
547if (name.ShouldNameExpressionBeTreatedAsExpressionInsteadOfType(_context.SemanticModel, out var nameBinding, out var container))
605var container = _context.SemanticModel.GetTypeInfo(identifier, _cancellationToken).Type;
655var container = _context.SemanticModel.GetTypeInfo(expression, _cancellationToken).Type;
665var container = _context.SemanticModel.GetTypeInfo(expression, _cancellationToken).Type;
680var container = _context.SemanticModel.GetTypeInfo(expression, _cancellationToken).Type;
696ITypeSymbol? containerType,
761private RecommendedSymbols GetSymbolsOffOfBoundExpressionWorker(SymbolInfo leftHandBinding, ExpressionSyntax originalExpression, ExpressionSyntax expression, ITypeSymbol? containerType, bool unwrapNullable, bool isForDereference)
869ITypeSymbol? containerType,
877if (symbol.IsStatic || symbol is ITypeSymbol)
906var container = GetContainerForUnnamedSymbols(semanticModel, originalExpression);
925private ITypeSymbol? GetContainerForUnnamedSymbols(SemanticModel semanticModel, ExpressionSyntax originalExpression)
927return originalExpression.ShouldNameExpressionBeTreatedAsExpressionInsteadOfType(_context.SemanticModel, out _, out var container)
932private void AddIndexers(ITypeSymbol container, ArrayBuilder<ISymbol> symbols)
Recommendations\CSharpRecommendationServiceRunner_Conversions.cs (12)
135private void AddConversions(ITypeSymbol container, ArrayBuilder<ISymbol> symbols)
145private static ITypeSymbol TryMakeNullable(Compilation compilation, ITypeSymbol container)
153ITypeSymbol container, INamedTypeSymbol containerWithoutNullable, ArrayBuilder<ISymbol> symbols)
201ITypeSymbol container, INamedTypeSymbol containerWithoutNullable, ArrayBuilder<ISymbol> symbols)
210public static ImmutableArray<SpecialType>? GetPredefinedNumericConversions(ITypeSymbol container)
229ITypeSymbol container, INamedTypeSymbol containerWithoutNullable, ArrayBuilder<ISymbol> symbols, ImmutableArray<SpecialType> specialTypes)
245static string CreateConversionDocumentationCommentXml(ITypeSymbol fromType, ITypeSymbol toType)
258private static IMethodSymbol CreateConversion(INamedTypeSymbol containingType, ITypeSymbol fromType, ITypeSymbol toType, string? documentationCommentXml)
266ITypeSymbol container, INamedTypeSymbol containerWithoutNullable, ArrayBuilder<ISymbol> symbols)
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\CSharp\Extensions\ExpressionSyntaxExtensions.cs (24)
906public static ITypeSymbol? GetTargetType(
936bool HasType(ExpressionSyntax expression, [NotNullWhen(true)] out ITypeSymbol? type)
942ITypeSymbol? GetTargetTypeForArgument(ArgumentSyntax argument)
946var tupleType = tupleExpression.GetTargetType(semanticModel, cancellationToken);
961ITypeSymbol? GetTargetTypeForAttributeArgument(AttributeArgumentSyntax argument)
964ITypeSymbol? GetTargetTypeForArrowExpression(ArrowExpressionClauseSyntax arrowExpression)
971ITypeSymbol? GetTargetTypeForReturnStatement(ReturnStatementSyntax returnStatement)
985ITypeSymbol? GetTargetTypeForEqualsValueClause(EqualsValueClauseSyntax equalsValue)
995ITypeSymbol? GetTargetTypedForCastExpression(CastExpressionSyntax castExpression)
998ITypeSymbol? GetTargetTypeForConditionalExpression(ConditionalExpressionSyntax conditionalExpression, ExpressionSyntax expression)
1001return HasType(conditionalExpression.WhenFalse, out var falseType) ? falseType : conditionalExpression.GetTargetType(semanticModel, cancellationToken);
1003return HasType(conditionalExpression.WhenTrue, out var trueType) ? trueType : conditionalExpression.GetTargetType(semanticModel, cancellationToken);
1008ITypeSymbol? GetTargetTypeForLambdaExpression(LambdaExpressionSyntax lambda, ExpressionSyntax expression)
1012ITypeSymbol? GetTargetTypeForSwitchExpressionArm(SwitchExpressionArmSyntax switchExpressionArm)
1019if (arm != switchExpressionArm && HasType(arm.Expression, out var armType))
1027ITypeSymbol? GetTargetTypeForCollectionElement(CollectionElementSyntax collectionElement)
1035var collectionTargetType = collectionExpression.GetTargetType(semanticModel, cancellationToken);
1055ITypeSymbol? GetTargetTypeForInitializerExpression(InitializerExpressionSyntax initializerExpression, ExpressionSyntax expression)
1059return HasType(arrayCreation.Type, out var elementType) ? elementType : null;
1066if (sibling != expression && HasType(sibling, out var siblingType))
1084ITypeSymbol? GetTargetTypeForAssignmentExpression(AssignmentExpressionSyntax assignmentExpression, ExpressionSyntax expression)
1086return expression == assignmentExpression.Right && HasType(assignmentExpression.Left, out var leftType) ? leftType : null;
1089ITypeSymbol? GetTargetTypeForBinaryExpression(BinaryExpressionSyntax binaryExpression, ExpressionSyntax expression)
1091return binaryExpression.Kind() == SyntaxKind.CoalesceExpression && binaryExpression.Right == expression && HasType(binaryExpression.Left, out var leftType) ? leftType : null;
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\CSharp\Simplification\Simplifiers\CastSimplifier.cs (34)
129var castedType = semanticModel.GetTypeInfo(castExpression.Type, cancellationToken).Type;
164var castedType = semanticModel.GetTypeInfo(castExpression.Type, cancellationToken).Type;
168var parentCastType = semanticModel.GetTypeInfo(parentCast.Type, cancellationToken).Type;
315var originalConvertedType = originalSemanticModel.GetTypeInfo(castNode.WalkUpParentheses(), cancellationToken).ConvertedType;
507var castedExpressionType = originalSemanticModel.GetTypeInfo(castedExpressionNode, cancellationToken).Type;
508var isType = originalSemanticModel.GetTypeInfo(isExpression.Right, cancellationToken).Type;
544var targetType = castNode.GetTargetType(originalSemanticModel, cancellationToken);
619ITypeSymbol originalConvertedType,
623var castedType = originalSemanticModel.GetTypeInfo(castNode, cancellationToken).Type;
698var castType = semanticModel.GetTypeInfo(castNode, cancellationToken).Type;
818var originalConvertedType = originalConversionOperation.Type;
819var rewrittenBitwiseNotConversionType = rewrittenBitwiseNotConversionOperation.Type;
832private static bool IsSignedIntegralOrIntPtrType(ITypeSymbol? type)
954var castType = originalSemanticModel.GetTypeInfo(castExpression, cancellationToken).Type;
988var otherSideType = originalSemanticModel.GetTypeInfo(otherSide, cancellationToken).Type;
989var thisSideRewrittenType = rewrittenSemanticModel.GetTypeInfo(rewrittenExpression, cancellationToken).Type;
1001var rewrittenConditionalConvertedType = rewrittenSemanticModel.GetTypeInfo(rewrittenConditionalOrSwitchExpression, cancellationToken).ConvertedType;
1036private static bool IsNullOrErrorType([NotNullWhen(false)] ITypeSymbol? type)
1159var castSideType = semanticModel.GetTypeInfo(castSide, cancellationToken).Type;
1160var castedExpressionType = semanticModel.GetTypeInfo(castExpression.Expression, cancellationToken).Type;
1162if (castSideType.IsNullable(out var underlyingType) && Equals(underlyingType, castedExpressionType))
1164var otherSideType = semanticModel.GetTypeInfo(otherSide, cancellationToken).Type;
1182var castType = semanticModel.GetTypeInfo(castNode, cancellationToken).Type;
1183var castedExpressionType = semanticModel.GetTypeInfo(castedExpressionNode, cancellationToken).Type;
1240private static bool IsFloatingPointType(ITypeSymbol? type)
1410var rewrittenType = rewrittenSemanticModel.GetTypeInfo(rewrittenExpression, cancellationToken).Type;
1525private static bool IsIntrinsicOrEnum(ITypeSymbol rewrittenType)
1533ITypeSymbol rewrittenType,
1572var originalMemberType = originalMemberSymbol.GetMemberType();
1573var rewrittenMemberType = rewrittenMemberSymbol.GetMemberType();
1623private static (ITypeSymbol? rewrittenConvertedType, Conversion rewrittenConversion) GetRewrittenInfo(
1626Conversion originalConversion, ITypeSymbol originalConvertedType,
1637var convertedType = originalConversion.IsIdentity ? originalConvertedType : originalSemanticModel.Compilation.ObjectType;
1641var rewrittenConvertedType = rewrittenSemanticModel.GetTypeInfo(rewrittenExpression, cancellationToken).ConvertedType;
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\CSharp\Utilities\SpeculationAnalyzer.cs (18)
267var originalParamType = this.OriginalSemanticModel.GetDeclaredSymbol(originalParam).Type;
268var replacedParamType = this.SpeculativeSemanticModel.GetDeclaredSymbol(replacedParam).Type;
386var originalExpressionType = originalExpressionTypeInfo.Type;
387var newExpressionType = newExpressionTypeInfo.Type;
435var originalCaseType = this.OriginalSemanticModel.GetTypeInfo(previousOriginalNode, this.CancellationToken).Type;
436var newCaseType = this.SpeculativeSemanticModel.GetTypeInfo(previousReplacedNode, this.CancellationToken).Type;
561var originalExpressionType = this.OriginalSemanticModel.GetTypeInfo(originalAnonymousObjectMemberDeclarator.Expression, this.CancellationToken).Type;
562var newExpressionType = this.SpeculativeSemanticModel.GetTypeInfo(replacedAnonymousObjectMemberDeclarator.Expression, this.CancellationToken).Type;
702var originalConvertedType = this.OriginalSemanticModel.GetTypeInfo(originalIsOrAsExpression.Right).Type;
703var newConvertedType = this.SpeculativeSemanticModel.GetTypeInfo(newIsOrAsExpression.Right).Type;
841protected override bool ConversionsAreCompatible(ExpressionSyntax originalExpression, ITypeSymbol originalTargetType, ExpressionSyntax newExpression, ITypeSymbol newTargetType)
889out ITypeSymbol elementType,
931protected override bool IsReferenceConversion(Compilation compilation, ITypeSymbol sourceType, ITypeSymbol targetType)
934protected override Conversion ClassifyConversion(SemanticModel model, ExpressionSyntax expression, ITypeSymbol targetType)
937protected override Conversion ClassifyConversion(SemanticModel model, ITypeSymbol originalType, ITypeSymbol targetType)
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\CSharp\CodeGeneration\ExpressionGenerator.cs (10)
34return typedConstant.Value is ITypeSymbol typeSymbol
54ITypeSymbol? type,
63if (type.IsNullable(out var underlyingType))
75internal static ExpressionSyntax GenerateNonEnumValueExpression(ITypeSymbol? type, object? value, bool canUseFieldReference)
118private static string DetermineSuffix(ITypeSymbol? type, object value)
172private static ExpressionSyntax GenerateDoubleLiteralExpression(ITypeSymbol? type, double value, bool canUseFieldReference)
201private static ExpressionSyntax GenerateSingleLiteralExpression(ITypeSymbol? type, float value, bool canUseFieldReference)
231ITypeSymbol? type, T value, IEnumerable<KeyValuePair<T, string>> constants,
242ITypeSymbol? type, T value, IEnumerable<KeyValuePair<T, string>> constants,
278private static ExpressionSyntax? GenerateFieldReference<T>(ITypeSymbol? type, T value, IEnumerable<KeyValuePair<T, string>> constants)
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\CSharp\LanguageServices\CSharpTypeInferenceService.TypeInferrer.cs (36)
35protected override bool IsUnusableType(ITypeSymbol otherSideType)
616private static IMethodSymbol Instantiate(IMethodSymbol method, IList<ITypeSymbol> invocationTypes)
640IDictionary<ITypeParameterSymbol, ITypeSymbol> bestMap = null;
641foreach (var type in invocationTypes)
662private static Dictionary<ITypeParameterSymbol, ITypeSymbol> DetermineTypeParameterMapping(ITypeSymbol inferredType, ITypeSymbol returnType)
664var result = new Dictionary<ITypeParameterSymbol, ITypeSymbol>();
669private static void DetermineTypeParameterMapping(ITypeSymbol inferredType, ITypeSymbol returnType, Dictionary<ITypeParameterSymbol, ITypeSymbol> result)
1122return leftTypes.Select(x => x.InferredType.IsNullable(out var underlying)
1134static ITypeSymbol MakeNullable(ITypeSymbol symbol, Compilation compilation)
1448var type = this.SemanticModel.GetTypeInfo(recursivePattern).ConvertedType;
1567var elementTypesBuilder = ArrayBuilder<ITypeSymbol>.GetInstance(subPatternCount);
1592private static ImmutableArray<NullableAnnotation> GetNullableAnnotations(ImmutableArray<ITypeSymbol> elementTypes)
1763var typeArg = delegateType?.TypeArguments.Length > 0
1781private ITypeSymbol InferTypeForFirstParameterOfLambda(
1796private ITypeSymbol InferTypeForFirstParameterOfParenthesizedLambda(
1805private ITypeSymbol InferTypeForFirstParameterOfSimpleLambda(
1812private ITypeSymbol InferTypeForFirstParameterOfLambda(
1819private ITypeSymbol InferTypeForFirstParameterOfLambda(
1837var type = InferTypeForFirstParameterOfLambda(parameterName, child.AsNode());
1990var memberType = memberSymbol.GetMemberType();
2002private ITypeSymbol UnwrapTaskLike(ITypeSymbol type, bool isAsync)
2043var type = symbol.GetMemberType();
2182var type = symbol.GetSymbolType();
2271var tupleType = GetTupleType(tupleExpression);
2280private ITypeSymbol GetTupleType(
2294out ImmutableArray<ITypeSymbol> elementTypes,
2300using var _1 = ArrayBuilder<ITypeSymbol>.GetInstance(out var elementTypesBuilder);
2338ArrayBuilder<ITypeSymbol> elementTypesBuilder,
2360ArrayBuilder<ITypeSymbol> elementTypesBuilder,
2363var tupleType = GetTupleType(tuple);
AddImport\SymbolReferenceFinder.cs (10)
205var typeSymbols = OfType<ITypeSymbol>(symbols);
232ITypeSymbol symbol,
311var propertyOrFieldType = symbol.GetSymbolType();
391ImmutableArray<SymbolResult<IMethodSymbol>> methodSymbols, ITypeSymbol typeSymbol)
448var type = _owner.GetQueryClauseInfo(_semanticModel, _node, cancellationToken);
472var type = GetAwaitInfo(_semanticModel, _syntaxFacts, _node);
497var type = GetCollectionExpressionType(_semanticModel, _syntaxFacts, _node);
522var type = GetCollectionExpressionType(_semanticModel, _syntaxFacts, _node);
547var type = _owner.GetDeconstructInfo(_semanticModel, _node, cancellationToken);
563SearchScope searchScope, string name, ITypeSymbol type, Func<IMethodSymbol, bool>? predicate, CancellationToken cancellationToken)
Completion\Providers\ImportCompletionProvider\AbstractTypeImportCompletionProvider.cs (1)
76Target: ITypeSymbol
Completion\Providers\ImportCompletionProvider\ExtensionMethodImportCompletionHelper.cs (8)
57ITypeSymbol receiverTypeSymbol,
59ImmutableArray<ITypeSymbol> targetTypesSymbols,
97ITypeSymbol receiverTypeSymbol,
99ImmutableArray<ITypeSymbol> targetTypes,
127Compilation compilation, ImmutableArray<IMethodSymbol> extentsionMethodSymbols, ImmutableArray<ITypeSymbol> targetTypeSymbols, CancellationToken cancellationToken)
129Dictionary<ITypeSymbol, bool> typeConvertibilityCache = [];
196Compilation compilation, IMethodSymbol methodSymbol, ImmutableArray<ITypeSymbol> targetTypeSymbols,
197Dictionary<ITypeSymbol, bool> typeConvertibilityCache)
Completion\Providers\ImportCompletionProvider\ExtensionMethodImportCompletionHelper.SymbolComputer.cs (16)
33private readonly ITypeSymbol _receiverTypeSymbol;
40private readonly ConcurrentDictionary<ITypeSymbol, bool> _checkedReceiverTypes = [];
45ITypeSymbol receiverTypeSymbol,
224MultiDictionary<ITypeSymbol, IMethodSymbol> matchingMethodSymbols,
233var declaredReceiverTypeInOriginatingCompilation = SymbolFinder.FindSimilarSymbols(declaredReceiverType, _originatingSemanticModel.Compilation, cancellationToken).FirstOrDefault();
291MultiDictionary<ITypeSymbol, IMethodSymbol> matchingMethodSymbols,
327private static IMethodSymbol? TryReduceExtensionMethod(IMethodSymbol methodSymbol, ITypeSymbol receiverTypeSymbol)
346private MultiDictionary<ITypeSymbol, IMethodSymbol> GetPotentialMatchingSymbolsFromAssembly(
352var builder = new MultiDictionary<ITypeSymbol, IMethodSymbol>();
387if (MatchExtensionMethod(methodSymbol, receiverTypeName, internalsVisible, out var receiverType))
398static bool MatchExtensionMethod(IMethodSymbol method, string filterReceiverTypeName, bool internalsVisible, out ITypeSymbol? receiverType)
479private static ImmutableArray<string> GetReceiverTypeNames(ITypeSymbol receiverTypeSymbol)
485static void AddNamesForTypeWorker(ITypeSymbol receiverTypeSymbol, PooledHashSet<string> builder)
489foreach (var constraintType in typeParameter.ConstraintTypes)
523private static string GetReceiverTypeName(ITypeSymbol typeSymbol)
531var elementType = arrayType.ElementType;
Completion\Providers\ImportCompletionProvider\ExtensionMethodImportCompletionHelper.SymbolComputer_Constraints.cs (18)
16private static bool CheckConstraints(ITypeSymbol receiverTypeSymbol, ITypeParameterSymbol typeParameter)
30private static bool SatisfiesInterfaceConstraint(ITypeSymbol receiverTypeSymbol, ITypeParameterSymbol typeParameter)
33private static bool SatisfiesBaseTypeConstraint(ITypeSymbol receiverTypeSymbol, ITypeParameterSymbol typeParameter)
36private static IEnumerable<ITypeSymbol> GetAllTypeParameterConstraintTypes(
39Func<ITypeSymbol, IEnumerable<ITypeSymbol>> getInheritanceTypes)
46foreach (var constraintType in currentTypeParameter.ConstraintTypes)
58foreach (var baseType in GetAllTypes(constraintType, typeKind, getInheritanceTypes))
66ITypeSymbol receiverTypeSymbol,
69Func<ITypeSymbol, IEnumerable<ITypeSymbol>> getInheritanceTypes)
76foreach (var constraintType in currentTypeParameter.ConstraintTypes)
88var originalConstraintType = constraintType.OriginalDefinition;
89foreach (var type in GetAllTypes(receiverTypeSymbol, constraintTypeKind, getInheritanceTypes))
104private static IEnumerable<ITypeSymbol> GetAllTypes(
105ITypeSymbol type, TypeKind typeKind, Func<ITypeSymbol, IEnumerable<ITypeSymbol>> getInheritanceTypes)
ConvertForEachToFor\AbstractConvertForEachToForCodeRefactoringProvider.cs (14)
133ITypeSymbol castType, SyntaxNode collectionVariable, SyntaxToken indexVariable)
180out var explicitCastInterface, out var collectionNameSuggestion, out var countName);
194out ITypeSymbol? explicitCastInterface, out string? collectionNameSuggestion, out string? countName)
201var foreachType = foreachVariable.Type;
207var collectionType = foreachCollection.Type;
292ITypeSymbol? explicitInterface = null;
340ITypeSymbol type1, ITypeSymbol type2, Compilation compilation)
346private static bool IsNullOrErrorType([NotNullWhen(false)] ITypeSymbol? type)
349private static IMethodSymbol? GetInterfaceMember(ITypeSymbol interfaceType, string memberName)
430ITypeSymbol? explicitCastInterface, ITypeSymbol forEachElementType,
437public ITypeSymbol? ExplicitCastInterface { get; } = explicitCastInterface;
438public ITypeSymbol ForEachElementType { get; } = forEachElementType;
ConvertForToForEach\AbstractConvertForToForEachCodeRefactoringProvider.cs (13)
51TExpressionSyntax collectionExpression, ITypeSymbol iterationVariableType);
119out var iterationType))
232INamedTypeSymbol containingType, ITypeSymbol type, string memberName) where TSymbol : class, ISymbol
239INamedTypeSymbol containingType, ITypeSymbol type, string memberName) where TSymbol : class, ISymbol
245INamedTypeSymbol containingType, ITypeSymbol collectionType,
247[NotNullWhen(true)] out ITypeSymbol? iterationType)
282INamedTypeSymbol ienumeratorType, [NotNullWhen(true)] out ITypeSymbol? iterationType)
284var getEnumeratorReturnType = getEnumeratorMethod.ReturnType;
315ITypeSymbol collectionType,
316ITypeSymbol iterationType,
345var indexerType = GetIndexerType(containingType, collectionType, semanticModel.Compilation.GetSpecialType(SpecialType.System_Collections_Generic_IEnumerable_T));
499private static ITypeSymbol? GetIndexerType(
501ITypeSymbol collectionType,
EditAndContinue\AbstractEditAndContinueAnalyzer.cs (13)
1962protected void AddRudeTypeUpdateAroundActiveStatement(RudeEditDiagnosticsBuilder diagnostics, SyntaxNode newNode, ITypeSymbol oldType, ITypeSymbol newType)
2145var oldType = oldModel.GetTypeInfo(oldTypedNodes[t], cancellationToken).Type;
2146var newType = newModel.GetTypeInfo(newTypedNodes[t], cancellationToken).Type;
2582protected static bool TypesEquivalent(ITypeSymbol? oldType, ITypeSymbol? newType, bool exact)
2583=> (exact ? s_exactSymbolEqualityComparer : (IEqualityComparer<ITypeSymbol?>)s_runtimeSymbolEqualityComparer.SignatureTypeEquivalenceComparer).Equals(oldType, newType);
2585protected static bool TypesEquivalent<T>(ImmutableArray<T> oldTypes, ImmutableArray<T> newTypes, bool exact) where T : ITypeSymbol
6592var oldType = GetType(oldSymbol);
6593var newType = GetType(newSymbol);
6680private static ITypeSymbol GetType(ISymbol localOrParameter)
6925TypedConstantKind.Type => TypesEquivalent((ITypeSymbol?)x.Value, (ITypeSymbol?)y.Value, exact: false),
src\Analyzers\Core\Analyzers\RemoveUnusedParametersAndValues\AbstractRemoveUnusedParametersAndValuesDiagnosticAnalyzer.SymbolStartAnalyzer.cs (1)
292ITypeSymbol containingType,
src\Analyzers\Core\CodeFixes\AddExplicitCast\AbstractAddExplicitCastCodeFixProvider.cs (11)
31protected abstract TExpressionSyntax Cast(TExpressionSyntax expression, ITypeSymbol type);
49protected ImmutableArray<(TExpressionSyntax node, ITypeSymbol type)> GetPotentialTargetTypes(
53using var _ = ArrayBuilder<(TExpressionSyntax node, ITypeSymbol type)>.GetInstance(out var candidates);
64ArrayBuilder<(TExpressionSyntax node, ITypeSymbol type)> candidates,
120ITypeSymbol conversionType,
143var castType = semanticModel.GetTypeInfo(castTypeNode, cancellationToken).Type;
161protected virtual (SyntaxNode finalTarget, SyntaxNode finalReplacement) Cast(SemanticModel semanticModel, TExpressionSyntax targetNode, ITypeSymbol conversionType)
164private static string GetSubItemName(SemanticModel semanticModel, int position, ITypeSymbol conversionType)
171private static ImmutableArray<(TExpressionSyntax, ITypeSymbol)> FilterValidPotentialConversionTypes(
174ArrayBuilder<(TExpressionSyntax node, ITypeSymbol type)> candidates)
179using var _ = ArrayBuilder<(TExpressionSyntax, ITypeSymbol)>.GetInstance(candidates.Count, out var validPotentialConversionTypes);
src\Analyzers\Core\CodeFixes\AddParameter\AbstractAddParameterCodeFixProvider.cs (4)
47protected abstract ITypeSymbol GetArgumentType(SyntaxNode argumentNode, SemanticModel semanticModel, CancellationToken cancellationToken);
402private async Task<(ITypeSymbol, RefKind)> GetArgumentTypeAndRefKindAsync(Document invocationDocument, TArgumentSyntax argument, CancellationToken cancellationToken)
406var argumentType = GetArgumentType(argument, semanticModel, cancellationToken);
537Compilation compilation, TypeInfo argumentTypeInfo, ITypeSymbol parameterType,
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\Utilities\AbstractSpeculationAnalyzer.cs (25)
102protected abstract TConversion ClassifyConversion(SemanticModel model, TExpressionSyntax expression, ITypeSymbol targetType);
103protected abstract TConversion ClassifyConversion(SemanticModel model, ITypeSymbol originalType, ITypeSymbol targetType);
105protected abstract bool ConversionsAreCompatible(TExpressionSyntax originalExpression, ITypeSymbol originalTargetType, TExpressionSyntax newExpression, ITypeSymbol newTargetType);
106protected abstract bool IsReferenceConversion(Compilation model, ITypeSymbol sourceType, ITypeSymbol targetType);
112SemanticModel model, TForEachStatementSyntax forEach, out IMethodSymbol getEnumeratorMethod, out ITypeSymbol elementType, out ImmutableArray<ILocalSymbol> localVariables);
305private bool ImplicitConversionsAreCompatible(TExpressionSyntax originalExpression, ITypeSymbol originalTargetType, TExpressionSyntax newExpression, ITypeSymbol newTargetType)
740var previousOriginalType = this.OriginalSemanticModel.GetTypeInfo(previousOriginalNode).Type;
741var previousReplacedType = this.SpeculativeSemanticModel.GetTypeInfo(previousReplacedNode).Type;
780GetForEachSymbols(this.OriginalSemanticModel, forEachStatement, out var originalGetEnumerator, out var originalElementType, out var originalLocalVariables);
781GetForEachSymbols(this.SpeculativeSemanticModel, newForEachStatement, out var newGetEnumerator, out var newElementType, out var newLocalVariables);
826var expressionType = this.SpeculativeSemanticModel.GetTypeInfo(newForEachStatementExpression, CancellationToken).ConvertedType;
849var originalThrowExpressionType = this.OriginalSemanticModel.GetTypeInfo(originalThrowExpression).Type;
851var newThrowExpressionType = this.SpeculativeSemanticModel.GetTypeInfo(newThrowExpression).Type;
961var originalTargetType = this.OriginalSemanticModel.GetTypeInfo(originalLeft).Type;
964var newTargetType = this.SpeculativeSemanticModel.GetTypeInfo(newLeft).Type;
997var newReceiverType = newReceiver != null
1036var receiverType = semanticModel.GetTypeInfo(receiver).Type;
1196ITypeSymbol originalTargetType,
1198ITypeSymbol newTargetType,
1213var originalConvertedTypeSymbol = this.OriginalSemanticModel.GetTypeInfo(originalExpression).ConvertedType;
1219var newConvertedTypeSymbol = this.SpeculativeSemanticModel.GetTypeInfo(newExpression).ConvertedType;
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Extensions\Symbols\ITypeSymbolExtensions.cs (101)
26public static bool IsIntegralType([NotNullWhen(returnValue: true)] this ITypeSymbol? type)
29public static bool IsSignedIntegralType([NotNullWhen(returnValue: true)] this ITypeSymbol? type)
32public static bool CanAddNullCheck([NotNullWhen(returnValue: true)] this ITypeSymbol? type)
43public static ImmutableArray<INamedTypeSymbol> GetAllInterfacesIncludingThis(this ITypeSymbol type)
51public static bool IsAbstractClass([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
54public static bool IsSystemVoid([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
57public static bool IsNullable([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
60public static bool IsNonNullableValueType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
64[NotNullWhen(true)] this ITypeSymbol? symbol,
65[NotNullWhen(true)] out ITypeSymbol? underlyingType)
77public static bool IsModuleType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
80public static bool IsInterfaceType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
83public static bool IsDelegateType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
86public static bool IsFunctionPointerType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
89public static bool IsStructType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
96this ITypeSymbol type,
110public static IEnumerable<ITypeSymbol> GetBaseTypesAndThis(this ITypeSymbol? type)
112var current = type;
120public static IEnumerable<INamedTypeSymbol> GetBaseTypes(this ITypeSymbol? type)
130public static IEnumerable<ITypeSymbol> GetContainingTypesAndThis(this ITypeSymbol? type)
132var current = type;
140public static IEnumerable<INamedTypeSymbol> GetContainingTypes(this ITypeSymbol type)
153this ITypeSymbol type, ITypeSymbol baseType, bool includeInterfaces)
166this ITypeSymbol type, ITypeSymbol baseType)
174this ITypeSymbol type, ITypeSymbol baseType)
176var originalBaseType = baseType.OriginalDefinition;
184IEnumerable<ITypeSymbol> baseTypes = (baseType.TypeKind == TypeKind.Interface) ? type.AllInterfaces : type.GetBaseTypes();
191this ITypeSymbol type, ITypeSymbol baseType)
193var originalBaseType = baseType.OriginalDefinition;
213this ITypeSymbol type, ITypeSymbol interfaceType)
215var originalInterfaceType = interfaceType.OriginalDefinition;
220this ITypeSymbol type, ITypeSymbol interfaceType)
225public static bool IsAttribute(this ITypeSymbol symbol)
243public static bool IsFormattableStringOrIFormattable([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
252this ITypeSymbol typeSymbol, bool allowDelegateAndEnumConstraints = false)
280public static bool IsNumericType([NotNullWhen(returnValue: true)] this ITypeSymbol? type)
306public static Accessibility DetermineMinimalAccessibility(this ITypeSymbol typeSymbol)
309public static bool ContainsAnonymousType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
325foreach (var typeArg in type.GetAllTypeArguments())
334public static string CreateParameterName(this ITypeSymbol type, bool capitalize = false)
355private static string GetParameterName(ITypeSymbol? type)
368public static bool IsSpecialType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
399public static bool CanSupportCollectionInitializer(this ITypeSymbol typeSymbol, ISymbol within)
410public static INamedTypeSymbol? GetDelegateType(this ITypeSymbol? typeSymbol, Compilation compilation)
417var typeArgument = ((INamedTypeSymbol)typeSymbol).TypeArguments[0];
430public static IEnumerable<T> GetAccessibleMembersInBaseTypes<T>(this ITypeSymbol containingType, ISymbol within) where T : class, ISymbol
439public static ImmutableArray<T> GetAccessibleMembersInThisAndBaseTypes<T>(this ITypeSymbol? containingType, ISymbol within) where T : class, ISymbol
449public static ImmutableArray<T> GetAccessibleMembersInThisAndBaseTypes<T>(this ITypeSymbol? containingType, string memberName, ISymbol within) where T : class, ISymbol
459public static bool? AreMoreSpecificThan(this IList<ITypeSymbol> t1, IList<ITypeSymbol> t2)
494public static IEnumerable<T> SelectAccessibleMembers<T>(this IEnumerable<ITypeSymbol>? types, ISymbol within) where T : class, ISymbol
504private static IEnumerable<T> SelectAccessibleMembers<T>(this IEnumerable<ITypeSymbol>? types, string memberName, ISymbol within) where T : class, ISymbol
514private static bool? IsMoreSpecificThan(this ITypeSymbol t1, ITypeSymbol t2)
592public static bool IsOrDerivesFromExceptionType([NotNullWhen(returnValue: true)] this ITypeSymbol? type, Compilation compilation)
599foreach (var baseType in type.GetBaseTypesAndThis())
610foreach (var constraint in ((ITypeParameterSymbol)type).ConstraintTypes)
625public static bool IsEnumType([NotNullWhen(true)] this ITypeSymbol? type)
628public static bool IsEnumType([NotNullWhen(true)] this ITypeSymbol? type, [NotNullWhen(true)] out INamedTypeSymbol? enumType)
640public static bool? IsMutableValueType(this ITypeSymbol type)
642if (type.IsNullable(out var underlyingType))
721static bool IsWellKnownImmutableValueType(ITypeSymbol type)
754public static bool IsDisposable([NotNullWhen(returnValue: true)] this ITypeSymbol? type, [NotNullWhen(returnValue: true)] ITypeSymbol? iDisposableType)
759public static ITypeSymbol WithNullableAnnotationFrom(this ITypeSymbol type, ITypeSymbol symbolForNullableAnnotation)
763public static ITypeSymbol? RemoveNullableIfPresent(this ITypeSymbol? symbol)
765if (symbol.IsNullable(out var underlyingType))
773public static bool IsSpanOrReadOnlySpan([NotNullWhen(true)] this ITypeSymbol? type)
776public static bool IsSpan([NotNullWhen(true)] this ITypeSymbol? type)
792public static bool IsInlineArray([NotNullWhen(true)] this ITypeSymbol? type)
797public static ITypeSymbol? RemoveUnavailableTypeParameters(
798this ITypeSymbol? type,
806private static ITypeSymbol? RemoveUnavailableTypeParameters(
807this ITypeSymbol? type,
815public static ITypeSymbol? RemoveAnonymousTypes(
816this ITypeSymbol? type,
823public static ITypeSymbol? RemoveUnnamedErrorTypes(
824this ITypeSymbol? type,
831this ITypeSymbol? type, ArrayBuilder<ITypeParameterSymbol> result)
837this ITypeSymbol? type, ArrayBuilder<ITypeParameterSymbol> result)
843this ITypeSymbol? type, ArrayBuilder<ITypeParameterSymbol> result, bool onlyMethodTypeParameters)
852public static IList<ITypeParameterSymbol> GetReferencedTypeParameters(this ITypeSymbol? type)
860public static ITypeSymbol? SubstituteTypes<TType1, TType2>(
861this ITypeSymbol? type,
864where TType1 : ITypeSymbol
865where TType2 : ITypeSymbol
871public static ITypeSymbol? SubstituteTypes<TType1, TType2>(
872this ITypeSymbol? type,
875where TType1 : ITypeSymbol
876where TType2 : ITypeSymbol
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\Utilities\AbstractSpeculationAnalyzer.cs (25)
102protected abstract TConversion ClassifyConversion(SemanticModel model, TExpressionSyntax expression, ITypeSymbol targetType);
103protected abstract TConversion ClassifyConversion(SemanticModel model, ITypeSymbol originalType, ITypeSymbol targetType);
105protected abstract bool ConversionsAreCompatible(TExpressionSyntax originalExpression, ITypeSymbol originalTargetType, TExpressionSyntax newExpression, ITypeSymbol newTargetType);
106protected abstract bool IsReferenceConversion(Compilation model, ITypeSymbol sourceType, ITypeSymbol targetType);
112SemanticModel model, TForEachStatementSyntax forEach, out IMethodSymbol getEnumeratorMethod, out ITypeSymbol elementType, out ImmutableArray<ILocalSymbol> localVariables);
305private bool ImplicitConversionsAreCompatible(TExpressionSyntax originalExpression, ITypeSymbol originalTargetType, TExpressionSyntax newExpression, ITypeSymbol newTargetType)
740var previousOriginalType = this.OriginalSemanticModel.GetTypeInfo(previousOriginalNode).Type;
741var previousReplacedType = this.SpeculativeSemanticModel.GetTypeInfo(previousReplacedNode).Type;
780GetForEachSymbols(this.OriginalSemanticModel, forEachStatement, out var originalGetEnumerator, out var originalElementType, out var originalLocalVariables);
781GetForEachSymbols(this.SpeculativeSemanticModel, newForEachStatement, out var newGetEnumerator, out var newElementType, out var newLocalVariables);
826var expressionType = this.SpeculativeSemanticModel.GetTypeInfo(newForEachStatementExpression, CancellationToken).ConvertedType;
849var originalThrowExpressionType = this.OriginalSemanticModel.GetTypeInfo(originalThrowExpression).Type;
851var newThrowExpressionType = this.SpeculativeSemanticModel.GetTypeInfo(newThrowExpression).Type;
961var originalTargetType = this.OriginalSemanticModel.GetTypeInfo(originalLeft).Type;
964var newTargetType = this.SpeculativeSemanticModel.GetTypeInfo(newLeft).Type;
997var newReceiverType = newReceiver != null
1036var receiverType = semanticModel.GetTypeInfo(receiver).Type;
1196ITypeSymbol originalTargetType,
1198ITypeSymbol newTargetType,
1213var originalConvertedTypeSymbol = this.OriginalSemanticModel.GetTypeInfo(originalExpression).ConvertedType;
1219var newConvertedTypeSymbol = this.SpeculativeSemanticModel.GetTypeInfo(newExpression).ConvertedType;
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Extensions\Symbols\ITypeSymbolExtensions.cs (101)
26public static bool IsIntegralType([NotNullWhen(returnValue: true)] this ITypeSymbol? type)
29public static bool IsSignedIntegralType([NotNullWhen(returnValue: true)] this ITypeSymbol? type)
32public static bool CanAddNullCheck([NotNullWhen(returnValue: true)] this ITypeSymbol? type)
43public static ImmutableArray<INamedTypeSymbol> GetAllInterfacesIncludingThis(this ITypeSymbol type)
51public static bool IsAbstractClass([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
54public static bool IsSystemVoid([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
57public static bool IsNullable([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
60public static bool IsNonNullableValueType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
64[NotNullWhen(true)] this ITypeSymbol? symbol,
65[NotNullWhen(true)] out ITypeSymbol? underlyingType)
77public static bool IsModuleType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
80public static bool IsInterfaceType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
83public static bool IsDelegateType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
86public static bool IsFunctionPointerType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
89public static bool IsStructType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
96this ITypeSymbol type,
110public static IEnumerable<ITypeSymbol> GetBaseTypesAndThis(this ITypeSymbol? type)
112var current = type;
120public static IEnumerable<INamedTypeSymbol> GetBaseTypes(this ITypeSymbol? type)
130public static IEnumerable<ITypeSymbol> GetContainingTypesAndThis(this ITypeSymbol? type)
132var current = type;
140public static IEnumerable<INamedTypeSymbol> GetContainingTypes(this ITypeSymbol type)
153this ITypeSymbol type, ITypeSymbol baseType, bool includeInterfaces)
166this ITypeSymbol type, ITypeSymbol baseType)
174this ITypeSymbol type, ITypeSymbol baseType)
176var originalBaseType = baseType.OriginalDefinition;
184IEnumerable<ITypeSymbol> baseTypes = (baseType.TypeKind == TypeKind.Interface) ? type.AllInterfaces : type.GetBaseTypes();
191this ITypeSymbol type, ITypeSymbol baseType)
193var originalBaseType = baseType.OriginalDefinition;
213this ITypeSymbol type, ITypeSymbol interfaceType)
215var originalInterfaceType = interfaceType.OriginalDefinition;
220this ITypeSymbol type, ITypeSymbol interfaceType)
225public static bool IsAttribute(this ITypeSymbol symbol)
243public static bool IsFormattableStringOrIFormattable([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
252this ITypeSymbol typeSymbol, bool allowDelegateAndEnumConstraints = false)
280public static bool IsNumericType([NotNullWhen(returnValue: true)] this ITypeSymbol? type)
306public static Accessibility DetermineMinimalAccessibility(this ITypeSymbol typeSymbol)
309public static bool ContainsAnonymousType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
325foreach (var typeArg in type.GetAllTypeArguments())
334public static string CreateParameterName(this ITypeSymbol type, bool capitalize = false)
355private static string GetParameterName(ITypeSymbol? type)
368public static bool IsSpecialType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
399public static bool CanSupportCollectionInitializer(this ITypeSymbol typeSymbol, ISymbol within)
410public static INamedTypeSymbol? GetDelegateType(this ITypeSymbol? typeSymbol, Compilation compilation)
417var typeArgument = ((INamedTypeSymbol)typeSymbol).TypeArguments[0];
430public static IEnumerable<T> GetAccessibleMembersInBaseTypes<T>(this ITypeSymbol containingType, ISymbol within) where T : class, ISymbol
439public static ImmutableArray<T> GetAccessibleMembersInThisAndBaseTypes<T>(this ITypeSymbol? containingType, ISymbol within) where T : class, ISymbol
449public static ImmutableArray<T> GetAccessibleMembersInThisAndBaseTypes<T>(this ITypeSymbol? containingType, string memberName, ISymbol within) where T : class, ISymbol
459public static bool? AreMoreSpecificThan(this IList<ITypeSymbol> t1, IList<ITypeSymbol> t2)
494public static IEnumerable<T> SelectAccessibleMembers<T>(this IEnumerable<ITypeSymbol>? types, ISymbol within) where T : class, ISymbol
504private static IEnumerable<T> SelectAccessibleMembers<T>(this IEnumerable<ITypeSymbol>? types, string memberName, ISymbol within) where T : class, ISymbol
514private static bool? IsMoreSpecificThan(this ITypeSymbol t1, ITypeSymbol t2)
592public static bool IsOrDerivesFromExceptionType([NotNullWhen(returnValue: true)] this ITypeSymbol? type, Compilation compilation)
599foreach (var baseType in type.GetBaseTypesAndThis())
610foreach (var constraint in ((ITypeParameterSymbol)type).ConstraintTypes)
625public static bool IsEnumType([NotNullWhen(true)] this ITypeSymbol? type)
628public static bool IsEnumType([NotNullWhen(true)] this ITypeSymbol? type, [NotNullWhen(true)] out INamedTypeSymbol? enumType)
640public static bool? IsMutableValueType(this ITypeSymbol type)
642if (type.IsNullable(out var underlyingType))
721static bool IsWellKnownImmutableValueType(ITypeSymbol type)
754public static bool IsDisposable([NotNullWhen(returnValue: true)] this ITypeSymbol? type, [NotNullWhen(returnValue: true)] ITypeSymbol? iDisposableType)
759public static ITypeSymbol WithNullableAnnotationFrom(this ITypeSymbol type, ITypeSymbol symbolForNullableAnnotation)
763public static ITypeSymbol? RemoveNullableIfPresent(this ITypeSymbol? symbol)
765if (symbol.IsNullable(out var underlyingType))
773public static bool IsSpanOrReadOnlySpan([NotNullWhen(true)] this ITypeSymbol? type)
776public static bool IsSpan([NotNullWhen(true)] this ITypeSymbol? type)
792public static bool IsInlineArray([NotNullWhen(true)] this ITypeSymbol? type)
797public static ITypeSymbol? RemoveUnavailableTypeParameters(
798this ITypeSymbol? type,
806private static ITypeSymbol? RemoveUnavailableTypeParameters(
807this ITypeSymbol? type,
815public static ITypeSymbol? RemoveAnonymousTypes(
816this ITypeSymbol? type,
823public static ITypeSymbol? RemoveUnnamedErrorTypes(
824this ITypeSymbol? type,
831this ITypeSymbol? type, ArrayBuilder<ITypeParameterSymbol> result)
837this ITypeSymbol? type, ArrayBuilder<ITypeParameterSymbol> result)
843this ITypeSymbol? type, ArrayBuilder<ITypeParameterSymbol> result, bool onlyMethodTypeParameters)
852public static IList<ITypeParameterSymbol> GetReferencedTypeParameters(this ITypeSymbol? type)
860public static ITypeSymbol? SubstituteTypes<TType1, TType2>(
861this ITypeSymbol? type,
864where TType1 : ITypeSymbol
865where TType2 : ITypeSymbol
871public static ITypeSymbol? SubstituteTypes<TType1, TType2>(
872this ITypeSymbol? type,
875where TType1 : ITypeSymbol
876where TType2 : ITypeSymbol
Editing\SyntaxGenerator.cs (20)
338private protected abstract SyntaxNode GenerateExpression(ITypeSymbol? type, object? value, bool canUseFieldReference);
1665/// <see langword="true"/> if the language requires a <see cref="TypeExpression(ITypeSymbol)"/>
1667/// <see cref="LocalDeclarationStatement(ITypeSymbol, string, SyntaxNode, bool)"/>.
1690public SyntaxNode LocalDeclarationStatement(ITypeSymbol type, string name, SyntaxNode? initializer = null, bool isConst = false)
1803public SyntaxNode CatchClause(ITypeSymbol type, string identifier, IEnumerable<SyntaxNode> statements)
1844public SyntaxNode DefaultExpression(ITypeSymbol type)
1913public SyntaxNode GenericName(string identifier, IEnumerable<ITypeSymbol> typeArguments)
1925public SyntaxNode GenericName(string identifier, params ITypeSymbol[] typeArguments)
1926=> GenericName(identifier, (IEnumerable<ITypeSymbol>)typeArguments);
1994public SyntaxNode TypeExpression(ITypeSymbol typeSymbol)
2002public SyntaxNode TypeExpression(ITypeSymbol typeSymbol, bool addImport)
2054public SyntaxNode TupleTypeExpression(IEnumerable<ITypeSymbol> elementTypes, IEnumerable<string>? elementNames = null)
2083public SyntaxNode TupleElementExpression(ITypeSymbol type, string? name = null)
2266public SyntaxNode ObjectCreationExpression(ITypeSymbol type, IEnumerable<SyntaxNode> arguments)
2278public SyntaxNode ObjectCreationExpression(ITypeSymbol type, params SyntaxNode[] arguments)
2333public SyntaxNode IsTypeExpression(SyntaxNode expression, ITypeSymbol type)
2344public SyntaxNode TryCastExpression(SyntaxNode expression, ITypeSymbol type)
2356public SyntaxNode CastExpression(ITypeSymbol type, SyntaxNode expression)
2368public SyntaxNode ConvertExpression(ITypeSymbol type, SyntaxNode expression)
2447public SyntaxNode LambdaParameter(string identifier, ITypeSymbol type)
Recommendations\AbstractRecommendationServiceRunner.cs (24)
44public abstract bool TryGetExplicitTypeOfLambdaParameter(SyntaxNode lambdaSyntax, int ordinalInLambda, [NotNullWhen(returnValue: true)] out ITypeSymbol explicitLambdaParameterType);
96var parameterTypeSymbols = ImmutableArray<ITypeSymbol>.Empty;
98if (TryGetExplicitTypeOfLambdaParameter(lambdaSyntax, parameter.Ordinal, out var explicitLambdaParameterType))
134private ImmutableArray<ITypeSymbol> SubstituteTypeParameters(ImmutableArray<ITypeSymbol> parameterTypeSymbols, SyntaxNode invocationExpression)
147using var _ = ArrayBuilder<ITypeSymbol>.GetInstance(out var concreteTypes);
153foreach (var parameterTypeSymbol in parameterTypeSymbols)
160var concreteType = typeArguments.ElementAtOrDefault(index);
184private ImmutableArray<ITypeSymbol> GetTypeSymbols(
193using var _ = ArrayBuilder<ITypeSymbol>.GetInstance(out var builder);
199if (!TryGetMatchingParameterTypeForArgument(method, argumentName, ordinalInInvocation, out var type))
237private bool TryGetMatchingParameterTypeForArgument(IMethodSymbol method, string argumentName, int ordinalInInvocation, out ITypeSymbol parameterType)
377if (unwrapNullable && namespaceOrType is ITypeSymbol typeSymbol)
407if (container is not ITypeSymbol containerType)
436static bool MatchesConstraints(ITypeSymbol originalContainerType, ImmutableArray<ITypeSymbol> constraintTypes)
443foreach (var constraintType in constraintTypes)
452static bool MatchesConstraint(ITypeSymbol originalContainerType, ITypeSymbol originalConstraintType)
470foreach (var constraintType in typeParameterContainer.ConstraintTypes)
495foreach (var constrainedType in typeParameterContainer.ConstraintTypes)
520static bool MatchesAnyBaseTypes(ITypeSymbol source, ITypeSymbol matched)
522for (var current = source; current != null; current = current.BaseType)
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\Utilities\AbstractSpeculationAnalyzer.cs (25)
102protected abstract TConversion ClassifyConversion(SemanticModel model, TExpressionSyntax expression, ITypeSymbol targetType);
103protected abstract TConversion ClassifyConversion(SemanticModel model, ITypeSymbol originalType, ITypeSymbol targetType);
105protected abstract bool ConversionsAreCompatible(TExpressionSyntax originalExpression, ITypeSymbol originalTargetType, TExpressionSyntax newExpression, ITypeSymbol newTargetType);
106protected abstract bool IsReferenceConversion(Compilation model, ITypeSymbol sourceType, ITypeSymbol targetType);
112SemanticModel model, TForEachStatementSyntax forEach, out IMethodSymbol getEnumeratorMethod, out ITypeSymbol elementType, out ImmutableArray<ILocalSymbol> localVariables);
305private bool ImplicitConversionsAreCompatible(TExpressionSyntax originalExpression, ITypeSymbol originalTargetType, TExpressionSyntax newExpression, ITypeSymbol newTargetType)
740var previousOriginalType = this.OriginalSemanticModel.GetTypeInfo(previousOriginalNode).Type;
741var previousReplacedType = this.SpeculativeSemanticModel.GetTypeInfo(previousReplacedNode).Type;
780GetForEachSymbols(this.OriginalSemanticModel, forEachStatement, out var originalGetEnumerator, out var originalElementType, out var originalLocalVariables);
781GetForEachSymbols(this.SpeculativeSemanticModel, newForEachStatement, out var newGetEnumerator, out var newElementType, out var newLocalVariables);
826var expressionType = this.SpeculativeSemanticModel.GetTypeInfo(newForEachStatementExpression, CancellationToken).ConvertedType;
849var originalThrowExpressionType = this.OriginalSemanticModel.GetTypeInfo(originalThrowExpression).Type;
851var newThrowExpressionType = this.SpeculativeSemanticModel.GetTypeInfo(newThrowExpression).Type;
961var originalTargetType = this.OriginalSemanticModel.GetTypeInfo(originalLeft).Type;
964var newTargetType = this.SpeculativeSemanticModel.GetTypeInfo(newLeft).Type;
997var newReceiverType = newReceiver != null
1036var receiverType = semanticModel.GetTypeInfo(receiver).Type;
1196ITypeSymbol originalTargetType,
1198ITypeSymbol newTargetType,
1213var originalConvertedTypeSymbol = this.OriginalSemanticModel.GetTypeInfo(originalExpression).ConvertedType;
1219var newConvertedTypeSymbol = this.SpeculativeSemanticModel.GetTypeInfo(newExpression).ConvertedType;
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Extensions\Symbols\ITypeSymbolExtensions.cs (101)
26public static bool IsIntegralType([NotNullWhen(returnValue: true)] this ITypeSymbol? type)
29public static bool IsSignedIntegralType([NotNullWhen(returnValue: true)] this ITypeSymbol? type)
32public static bool CanAddNullCheck([NotNullWhen(returnValue: true)] this ITypeSymbol? type)
43public static ImmutableArray<INamedTypeSymbol> GetAllInterfacesIncludingThis(this ITypeSymbol type)
51public static bool IsAbstractClass([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
54public static bool IsSystemVoid([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
57public static bool IsNullable([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
60public static bool IsNonNullableValueType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
64[NotNullWhen(true)] this ITypeSymbol? symbol,
65[NotNullWhen(true)] out ITypeSymbol? underlyingType)
77public static bool IsModuleType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
80public static bool IsInterfaceType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
83public static bool IsDelegateType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
86public static bool IsFunctionPointerType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
89public static bool IsStructType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
96this ITypeSymbol type,
110public static IEnumerable<ITypeSymbol> GetBaseTypesAndThis(this ITypeSymbol? type)
112var current = type;
120public static IEnumerable<INamedTypeSymbol> GetBaseTypes(this ITypeSymbol? type)
130public static IEnumerable<ITypeSymbol> GetContainingTypesAndThis(this ITypeSymbol? type)
132var current = type;
140public static IEnumerable<INamedTypeSymbol> GetContainingTypes(this ITypeSymbol type)
153this ITypeSymbol type, ITypeSymbol baseType, bool includeInterfaces)
166this ITypeSymbol type, ITypeSymbol baseType)
174this ITypeSymbol type, ITypeSymbol baseType)
176var originalBaseType = baseType.OriginalDefinition;
184IEnumerable<ITypeSymbol> baseTypes = (baseType.TypeKind == TypeKind.Interface) ? type.AllInterfaces : type.GetBaseTypes();
191this ITypeSymbol type, ITypeSymbol baseType)
193var originalBaseType = baseType.OriginalDefinition;
213this ITypeSymbol type, ITypeSymbol interfaceType)
215var originalInterfaceType = interfaceType.OriginalDefinition;
220this ITypeSymbol type, ITypeSymbol interfaceType)
225public static bool IsAttribute(this ITypeSymbol symbol)
243public static bool IsFormattableStringOrIFormattable([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
252this ITypeSymbol typeSymbol, bool allowDelegateAndEnumConstraints = false)
280public static bool IsNumericType([NotNullWhen(returnValue: true)] this ITypeSymbol? type)
306public static Accessibility DetermineMinimalAccessibility(this ITypeSymbol typeSymbol)
309public static bool ContainsAnonymousType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
325foreach (var typeArg in type.GetAllTypeArguments())
334public static string CreateParameterName(this ITypeSymbol type, bool capitalize = false)
355private static string GetParameterName(ITypeSymbol? type)
368public static bool IsSpecialType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
399public static bool CanSupportCollectionInitializer(this ITypeSymbol typeSymbol, ISymbol within)
410public static INamedTypeSymbol? GetDelegateType(this ITypeSymbol? typeSymbol, Compilation compilation)
417var typeArgument = ((INamedTypeSymbol)typeSymbol).TypeArguments[0];
430public static IEnumerable<T> GetAccessibleMembersInBaseTypes<T>(this ITypeSymbol containingType, ISymbol within) where T : class, ISymbol
439public static ImmutableArray<T> GetAccessibleMembersInThisAndBaseTypes<T>(this ITypeSymbol? containingType, ISymbol within) where T : class, ISymbol
449public static ImmutableArray<T> GetAccessibleMembersInThisAndBaseTypes<T>(this ITypeSymbol? containingType, string memberName, ISymbol within) where T : class, ISymbol
459public static bool? AreMoreSpecificThan(this IList<ITypeSymbol> t1, IList<ITypeSymbol> t2)
494public static IEnumerable<T> SelectAccessibleMembers<T>(this IEnumerable<ITypeSymbol>? types, ISymbol within) where T : class, ISymbol
504private static IEnumerable<T> SelectAccessibleMembers<T>(this IEnumerable<ITypeSymbol>? types, string memberName, ISymbol within) where T : class, ISymbol
514private static bool? IsMoreSpecificThan(this ITypeSymbol t1, ITypeSymbol t2)
592public static bool IsOrDerivesFromExceptionType([NotNullWhen(returnValue: true)] this ITypeSymbol? type, Compilation compilation)
599foreach (var baseType in type.GetBaseTypesAndThis())
610foreach (var constraint in ((ITypeParameterSymbol)type).ConstraintTypes)
625public static bool IsEnumType([NotNullWhen(true)] this ITypeSymbol? type)
628public static bool IsEnumType([NotNullWhen(true)] this ITypeSymbol? type, [NotNullWhen(true)] out INamedTypeSymbol? enumType)
640public static bool? IsMutableValueType(this ITypeSymbol type)
642if (type.IsNullable(out var underlyingType))
721static bool IsWellKnownImmutableValueType(ITypeSymbol type)
754public static bool IsDisposable([NotNullWhen(returnValue: true)] this ITypeSymbol? type, [NotNullWhen(returnValue: true)] ITypeSymbol? iDisposableType)
759public static ITypeSymbol WithNullableAnnotationFrom(this ITypeSymbol type, ITypeSymbol symbolForNullableAnnotation)
763public static ITypeSymbol? RemoveNullableIfPresent(this ITypeSymbol? symbol)
765if (symbol.IsNullable(out var underlyingType))
773public static bool IsSpanOrReadOnlySpan([NotNullWhen(true)] this ITypeSymbol? type)
776public static bool IsSpan([NotNullWhen(true)] this ITypeSymbol? type)
792public static bool IsInlineArray([NotNullWhen(true)] this ITypeSymbol? type)
797public static ITypeSymbol? RemoveUnavailableTypeParameters(
798this ITypeSymbol? type,
806private static ITypeSymbol? RemoveUnavailableTypeParameters(
807this ITypeSymbol? type,
815public static ITypeSymbol? RemoveAnonymousTypes(
816this ITypeSymbol? type,
823public static ITypeSymbol? RemoveUnnamedErrorTypes(
824this ITypeSymbol? type,
831this ITypeSymbol? type, ArrayBuilder<ITypeParameterSymbol> result)
837this ITypeSymbol? type, ArrayBuilder<ITypeParameterSymbol> result)
843this ITypeSymbol? type, ArrayBuilder<ITypeParameterSymbol> result, bool onlyMethodTypeParameters)
852public static IList<ITypeParameterSymbol> GetReferencedTypeParameters(this ITypeSymbol? type)
860public static ITypeSymbol? SubstituteTypes<TType1, TType2>(
861this ITypeSymbol? type,
864where TType1 : ITypeSymbol
865where TType2 : ITypeSymbol
871public static ITypeSymbol? SubstituteTypes<TType1, TType2>(
872this ITypeSymbol? type,
875where TType1 : ITypeSymbol
876where TType2 : ITypeSymbol
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\Core\CodeGeneration\CodeGenerationSymbolFactory.cs (18)
30DeclarationModifiers modifiers, ITypeSymbol type,
47ITypeSymbol type,
79ITypeSymbol type, RefKind refKind, ImmutableArray<IPropertySymbol> explicitInterfaceImplementations, string name,
106ITypeSymbol type, string name,
152ITypeSymbol? returnType,
174ITypeSymbol? returnType,
195ITypeSymbol returnType,
220ITypeSymbol toType,
248ITypeSymbol toType,
264public static IParameterSymbol CreateParameterSymbol(ITypeSymbol type, string name)
267public static IParameterSymbol CreateParameterSymbol(RefKind refKind, ITypeSymbol type, string name)
277ImmutableArray<AttributeData> attributes, RefKind refKind, bool isParams, ITypeSymbol type, string name, bool isOptional = false, bool hasDefaultValue = false, object? defaultValue = null)
290ITypeSymbol? type = null,
331ImmutableArray<ITypeSymbol> constraintTypes,
347public static IPointerTypeSymbol CreatePointerTypeSymbol(ITypeSymbol pointedAtType)
353public static IArrayTypeSymbol CreateArrayTypeSymbol(ITypeSymbol elementType, int rank = 1, NullableAnnotation nullableAnnotation = NullableAnnotation.None)
463ITypeSymbol returnType,
520ITypeSymbol? returnType = null,
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\Core\CodeGeneration\Symbols\CodeGenerationArrayTypeSymbol.cs (2)
10internal sealed class CodeGenerationArrayTypeSymbol(ITypeSymbol elementType, int rank, NullableAnnotation nullableAnnotation) : CodeGenerationTypeSymbol(null, null, default, Accessibility.NotApplicable, default, string.Empty, SpecialType.None, nullableAnnotation), IArrayTypeSymbol
12public ITypeSymbol ElementType { get; } = elementType;
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\Core\CodeGeneration\Symbols\CodeGenerationConversionSymbol.cs (1)
15ITypeSymbol toType,
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\Core\CodeGeneration\Symbols\CodeGenerationOperatorSymbol.cs (1)
15ITypeSymbol returnType,
DefaultableTypeShouldHaveDefaultableFieldsAnalyzer.cs (6)
50var knownNonDefaultableTypes = new ConcurrentDictionary<ITypeSymbol, bool>();
56private static void AnalyzeField(SymbolAnalysisContext context, INamedTypeSymbol nonDefaultableAttribute, ConcurrentDictionary<ITypeSymbol, bool> knownNonDefaultableTypes)
61private static void AnalyzeNamedType(SymbolAnalysisContext context, INamedTypeSymbol nonDefaultableAttribute, ConcurrentDictionary<ITypeSymbol, bool> knownNonDefaultableTypes)
76private static void AnalyzeField(SymbolAnalysisContext originalContext, IFieldSymbol field, INamedTypeSymbol nonDefaultableAttribute, ConcurrentDictionary<ITypeSymbol, bool> knownNonDefaultableTypes)
110private static bool IsDefaultable(ITypeSymbol type, INamedTypeSymbol nonDefaultableAttribute, ConcurrentDictionary<ITypeSymbol, bool> knownNonDefaultableTypes)
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\Utilities\AbstractSpeculationAnalyzer.cs (25)
102protected abstract TConversion ClassifyConversion(SemanticModel model, TExpressionSyntax expression, ITypeSymbol targetType);
103protected abstract TConversion ClassifyConversion(SemanticModel model, ITypeSymbol originalType, ITypeSymbol targetType);
105protected abstract bool ConversionsAreCompatible(TExpressionSyntax originalExpression, ITypeSymbol originalTargetType, TExpressionSyntax newExpression, ITypeSymbol newTargetType);
106protected abstract bool IsReferenceConversion(Compilation model, ITypeSymbol sourceType, ITypeSymbol targetType);
112SemanticModel model, TForEachStatementSyntax forEach, out IMethodSymbol getEnumeratorMethod, out ITypeSymbol elementType, out ImmutableArray<ILocalSymbol> localVariables);
305private bool ImplicitConversionsAreCompatible(TExpressionSyntax originalExpression, ITypeSymbol originalTargetType, TExpressionSyntax newExpression, ITypeSymbol newTargetType)
740var previousOriginalType = this.OriginalSemanticModel.GetTypeInfo(previousOriginalNode).Type;
741var previousReplacedType = this.SpeculativeSemanticModel.GetTypeInfo(previousReplacedNode).Type;
780GetForEachSymbols(this.OriginalSemanticModel, forEachStatement, out var originalGetEnumerator, out var originalElementType, out var originalLocalVariables);
781GetForEachSymbols(this.SpeculativeSemanticModel, newForEachStatement, out var newGetEnumerator, out var newElementType, out var newLocalVariables);
826var expressionType = this.SpeculativeSemanticModel.GetTypeInfo(newForEachStatementExpression, CancellationToken).ConvertedType;
849var originalThrowExpressionType = this.OriginalSemanticModel.GetTypeInfo(originalThrowExpression).Type;
851var newThrowExpressionType = this.SpeculativeSemanticModel.GetTypeInfo(newThrowExpression).Type;
961var originalTargetType = this.OriginalSemanticModel.GetTypeInfo(originalLeft).Type;
964var newTargetType = this.SpeculativeSemanticModel.GetTypeInfo(newLeft).Type;
997var newReceiverType = newReceiver != null
1036var receiverType = semanticModel.GetTypeInfo(receiver).Type;
1196ITypeSymbol originalTargetType,
1198ITypeSymbol newTargetType,
1213var originalConvertedTypeSymbol = this.OriginalSemanticModel.GetTypeInfo(originalExpression).ConvertedType;
1219var newConvertedTypeSymbol = this.SpeculativeSemanticModel.GetTypeInfo(newExpression).ConvertedType;
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Extensions\Symbols\ITypeSymbolExtensions.cs (101)
26public static bool IsIntegralType([NotNullWhen(returnValue: true)] this ITypeSymbol? type)
29public static bool IsSignedIntegralType([NotNullWhen(returnValue: true)] this ITypeSymbol? type)
32public static bool CanAddNullCheck([NotNullWhen(returnValue: true)] this ITypeSymbol? type)
43public static ImmutableArray<INamedTypeSymbol> GetAllInterfacesIncludingThis(this ITypeSymbol type)
51public static bool IsAbstractClass([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
54public static bool IsSystemVoid([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
57public static bool IsNullable([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
60public static bool IsNonNullableValueType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
64[NotNullWhen(true)] this ITypeSymbol? symbol,
65[NotNullWhen(true)] out ITypeSymbol? underlyingType)
77public static bool IsModuleType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
80public static bool IsInterfaceType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
83public static bool IsDelegateType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
86public static bool IsFunctionPointerType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
89public static bool IsStructType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
96this ITypeSymbol type,
110public static IEnumerable<ITypeSymbol> GetBaseTypesAndThis(this ITypeSymbol? type)
112var current = type;
120public static IEnumerable<INamedTypeSymbol> GetBaseTypes(this ITypeSymbol? type)
130public static IEnumerable<ITypeSymbol> GetContainingTypesAndThis(this ITypeSymbol? type)
132var current = type;
140public static IEnumerable<INamedTypeSymbol> GetContainingTypes(this ITypeSymbol type)
153this ITypeSymbol type, ITypeSymbol baseType, bool includeInterfaces)
166this ITypeSymbol type, ITypeSymbol baseType)
174this ITypeSymbol type, ITypeSymbol baseType)
176var originalBaseType = baseType.OriginalDefinition;
184IEnumerable<ITypeSymbol> baseTypes = (baseType.TypeKind == TypeKind.Interface) ? type.AllInterfaces : type.GetBaseTypes();
191this ITypeSymbol type, ITypeSymbol baseType)
193var originalBaseType = baseType.OriginalDefinition;
213this ITypeSymbol type, ITypeSymbol interfaceType)
215var originalInterfaceType = interfaceType.OriginalDefinition;
220this ITypeSymbol type, ITypeSymbol interfaceType)
225public static bool IsAttribute(this ITypeSymbol symbol)
243public static bool IsFormattableStringOrIFormattable([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
252this ITypeSymbol typeSymbol, bool allowDelegateAndEnumConstraints = false)
280public static bool IsNumericType([NotNullWhen(returnValue: true)] this ITypeSymbol? type)
306public static Accessibility DetermineMinimalAccessibility(this ITypeSymbol typeSymbol)
309public static bool ContainsAnonymousType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
325foreach (var typeArg in type.GetAllTypeArguments())
334public static string CreateParameterName(this ITypeSymbol type, bool capitalize = false)
355private static string GetParameterName(ITypeSymbol? type)
368public static bool IsSpecialType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
399public static bool CanSupportCollectionInitializer(this ITypeSymbol typeSymbol, ISymbol within)
410public static INamedTypeSymbol? GetDelegateType(this ITypeSymbol? typeSymbol, Compilation compilation)
417var typeArgument = ((INamedTypeSymbol)typeSymbol).TypeArguments[0];
430public static IEnumerable<T> GetAccessibleMembersInBaseTypes<T>(this ITypeSymbol containingType, ISymbol within) where T : class, ISymbol
439public static ImmutableArray<T> GetAccessibleMembersInThisAndBaseTypes<T>(this ITypeSymbol? containingType, ISymbol within) where T : class, ISymbol
449public static ImmutableArray<T> GetAccessibleMembersInThisAndBaseTypes<T>(this ITypeSymbol? containingType, string memberName, ISymbol within) where T : class, ISymbol
459public static bool? AreMoreSpecificThan(this IList<ITypeSymbol> t1, IList<ITypeSymbol> t2)
494public static IEnumerable<T> SelectAccessibleMembers<T>(this IEnumerable<ITypeSymbol>? types, ISymbol within) where T : class, ISymbol
504private static IEnumerable<T> SelectAccessibleMembers<T>(this IEnumerable<ITypeSymbol>? types, string memberName, ISymbol within) where T : class, ISymbol
514private static bool? IsMoreSpecificThan(this ITypeSymbol t1, ITypeSymbol t2)
592public static bool IsOrDerivesFromExceptionType([NotNullWhen(returnValue: true)] this ITypeSymbol? type, Compilation compilation)
599foreach (var baseType in type.GetBaseTypesAndThis())
610foreach (var constraint in ((ITypeParameterSymbol)type).ConstraintTypes)
625public static bool IsEnumType([NotNullWhen(true)] this ITypeSymbol? type)
628public static bool IsEnumType([NotNullWhen(true)] this ITypeSymbol? type, [NotNullWhen(true)] out INamedTypeSymbol? enumType)
640public static bool? IsMutableValueType(this ITypeSymbol type)
642if (type.IsNullable(out var underlyingType))
721static bool IsWellKnownImmutableValueType(ITypeSymbol type)
754public static bool IsDisposable([NotNullWhen(returnValue: true)] this ITypeSymbol? type, [NotNullWhen(returnValue: true)] ITypeSymbol? iDisposableType)
759public static ITypeSymbol WithNullableAnnotationFrom(this ITypeSymbol type, ITypeSymbol symbolForNullableAnnotation)
763public static ITypeSymbol? RemoveNullableIfPresent(this ITypeSymbol? symbol)
765if (symbol.IsNullable(out var underlyingType))
773public static bool IsSpanOrReadOnlySpan([NotNullWhen(true)] this ITypeSymbol? type)
776public static bool IsSpan([NotNullWhen(true)] this ITypeSymbol? type)
792public static bool IsInlineArray([NotNullWhen(true)] this ITypeSymbol? type)
797public static ITypeSymbol? RemoveUnavailableTypeParameters(
798this ITypeSymbol? type,
806private static ITypeSymbol? RemoveUnavailableTypeParameters(
807this ITypeSymbol? type,
815public static ITypeSymbol? RemoveAnonymousTypes(
816this ITypeSymbol? type,
823public static ITypeSymbol? RemoveUnnamedErrorTypes(
824this ITypeSymbol? type,
831this ITypeSymbol? type, ArrayBuilder<ITypeParameterSymbol> result)
837this ITypeSymbol? type, ArrayBuilder<ITypeParameterSymbol> result)
843this ITypeSymbol? type, ArrayBuilder<ITypeParameterSymbol> result, bool onlyMethodTypeParameters)
852public static IList<ITypeParameterSymbol> GetReferencedTypeParameters(this ITypeSymbol? type)
860public static ITypeSymbol? SubstituteTypes<TType1, TType2>(
861this ITypeSymbol? type,
864where TType1 : ITypeSymbol
865where TType2 : ITypeSymbol
871public static ITypeSymbol? SubstituteTypes<TType1, TType2>(
872this ITypeSymbol? type,
875where TType1 : ITypeSymbol
876where TType2 : ITypeSymbol
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\Core\CodeGeneration\CodeGenerationSymbolFactory.cs (18)
30DeclarationModifiers modifiers, ITypeSymbol type,
47ITypeSymbol type,
79ITypeSymbol type, RefKind refKind, ImmutableArray<IPropertySymbol> explicitInterfaceImplementations, string name,
106ITypeSymbol type, string name,
152ITypeSymbol? returnType,
174ITypeSymbol? returnType,
195ITypeSymbol returnType,
220ITypeSymbol toType,
248ITypeSymbol toType,
264public static IParameterSymbol CreateParameterSymbol(ITypeSymbol type, string name)
267public static IParameterSymbol CreateParameterSymbol(RefKind refKind, ITypeSymbol type, string name)
277ImmutableArray<AttributeData> attributes, RefKind refKind, bool isParams, ITypeSymbol type, string name, bool isOptional = false, bool hasDefaultValue = false, object? defaultValue = null)
290ITypeSymbol? type = null,
331ImmutableArray<ITypeSymbol> constraintTypes,
347public static IPointerTypeSymbol CreatePointerTypeSymbol(ITypeSymbol pointedAtType)
353public static IArrayTypeSymbol CreateArrayTypeSymbol(ITypeSymbol elementType, int rank = 1, NullableAnnotation nullableAnnotation = NullableAnnotation.None)
463ITypeSymbol returnType,
520ITypeSymbol? returnType = null,
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\Core\CodeGeneration\Symbols\CodeGenerationArrayTypeSymbol.cs (2)
10internal sealed class CodeGenerationArrayTypeSymbol(ITypeSymbol elementType, int rank, NullableAnnotation nullableAnnotation) : CodeGenerationTypeSymbol(null, null, default, Accessibility.NotApplicable, default, string.Empty, SpecialType.None, nullableAnnotation), IArrayTypeSymbol
12public ITypeSymbol ElementType { get; } = elementType;
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\Core\CodeGeneration\Symbols\CodeGenerationConversionSymbol.cs (1)
15ITypeSymbol toType,
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\Core\CodeGeneration\Symbols\CodeGenerationOperatorSymbol.cs (1)
15ITypeSymbol returnType,
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\CSharp\Extensions\ExpressionSyntaxExtensions.cs (24)
906public static ITypeSymbol? GetTargetType(
936bool HasType(ExpressionSyntax expression, [NotNullWhen(true)] out ITypeSymbol? type)
942ITypeSymbol? GetTargetTypeForArgument(ArgumentSyntax argument)
946var tupleType = tupleExpression.GetTargetType(semanticModel, cancellationToken);
961ITypeSymbol? GetTargetTypeForAttributeArgument(AttributeArgumentSyntax argument)
964ITypeSymbol? GetTargetTypeForArrowExpression(ArrowExpressionClauseSyntax arrowExpression)
971ITypeSymbol? GetTargetTypeForReturnStatement(ReturnStatementSyntax returnStatement)
985ITypeSymbol? GetTargetTypeForEqualsValueClause(EqualsValueClauseSyntax equalsValue)
995ITypeSymbol? GetTargetTypedForCastExpression(CastExpressionSyntax castExpression)
998ITypeSymbol? GetTargetTypeForConditionalExpression(ConditionalExpressionSyntax conditionalExpression, ExpressionSyntax expression)
1001return HasType(conditionalExpression.WhenFalse, out var falseType) ? falseType : conditionalExpression.GetTargetType(semanticModel, cancellationToken);
1003return HasType(conditionalExpression.WhenTrue, out var trueType) ? trueType : conditionalExpression.GetTargetType(semanticModel, cancellationToken);
1008ITypeSymbol? GetTargetTypeForLambdaExpression(LambdaExpressionSyntax lambda, ExpressionSyntax expression)
1012ITypeSymbol? GetTargetTypeForSwitchExpressionArm(SwitchExpressionArmSyntax switchExpressionArm)
1019if (arm != switchExpressionArm && HasType(arm.Expression, out var armType))
1027ITypeSymbol? GetTargetTypeForCollectionElement(CollectionElementSyntax collectionElement)
1035var collectionTargetType = collectionExpression.GetTargetType(semanticModel, cancellationToken);
1055ITypeSymbol? GetTargetTypeForInitializerExpression(InitializerExpressionSyntax initializerExpression, ExpressionSyntax expression)
1059return HasType(arrayCreation.Type, out var elementType) ? elementType : null;
1066if (sibling != expression && HasType(sibling, out var siblingType))
1084ITypeSymbol? GetTargetTypeForAssignmentExpression(AssignmentExpressionSyntax assignmentExpression, ExpressionSyntax expression)
1086return expression == assignmentExpression.Right && HasType(assignmentExpression.Left, out var leftType) ? leftType : null;
1089ITypeSymbol? GetTargetTypeForBinaryExpression(BinaryExpressionSyntax binaryExpression, ExpressionSyntax expression)
1091return binaryExpression.Kind() == SyntaxKind.CoalesceExpression && binaryExpression.Right == expression && HasType(binaryExpression.Left, out var leftType) ? leftType : null;
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\CSharp\Simplification\Simplifiers\CastSimplifier.cs (34)
129var castedType = semanticModel.GetTypeInfo(castExpression.Type, cancellationToken).Type;
164var castedType = semanticModel.GetTypeInfo(castExpression.Type, cancellationToken).Type;
168var parentCastType = semanticModel.GetTypeInfo(parentCast.Type, cancellationToken).Type;
315var originalConvertedType = originalSemanticModel.GetTypeInfo(castNode.WalkUpParentheses(), cancellationToken).ConvertedType;
507var castedExpressionType = originalSemanticModel.GetTypeInfo(castedExpressionNode, cancellationToken).Type;
508var isType = originalSemanticModel.GetTypeInfo(isExpression.Right, cancellationToken).Type;
544var targetType = castNode.GetTargetType(originalSemanticModel, cancellationToken);
619ITypeSymbol originalConvertedType,
623var castedType = originalSemanticModel.GetTypeInfo(castNode, cancellationToken).Type;
698var castType = semanticModel.GetTypeInfo(castNode, cancellationToken).Type;
818var originalConvertedType = originalConversionOperation.Type;
819var rewrittenBitwiseNotConversionType = rewrittenBitwiseNotConversionOperation.Type;
832private static bool IsSignedIntegralOrIntPtrType(ITypeSymbol? type)
954var castType = originalSemanticModel.GetTypeInfo(castExpression, cancellationToken).Type;
988var otherSideType = originalSemanticModel.GetTypeInfo(otherSide, cancellationToken).Type;
989var thisSideRewrittenType = rewrittenSemanticModel.GetTypeInfo(rewrittenExpression, cancellationToken).Type;
1001var rewrittenConditionalConvertedType = rewrittenSemanticModel.GetTypeInfo(rewrittenConditionalOrSwitchExpression, cancellationToken).ConvertedType;
1036private static bool IsNullOrErrorType([NotNullWhen(false)] ITypeSymbol? type)
1159var castSideType = semanticModel.GetTypeInfo(castSide, cancellationToken).Type;
1160var castedExpressionType = semanticModel.GetTypeInfo(castExpression.Expression, cancellationToken).Type;
1162if (castSideType.IsNullable(out var underlyingType) && Equals(underlyingType, castedExpressionType))
1164var otherSideType = semanticModel.GetTypeInfo(otherSide, cancellationToken).Type;
1182var castType = semanticModel.GetTypeInfo(castNode, cancellationToken).Type;
1183var castedExpressionType = semanticModel.GetTypeInfo(castedExpressionNode, cancellationToken).Type;
1240private static bool IsFloatingPointType(ITypeSymbol? type)
1410var rewrittenType = rewrittenSemanticModel.GetTypeInfo(rewrittenExpression, cancellationToken).Type;
1525private static bool IsIntrinsicOrEnum(ITypeSymbol rewrittenType)
1533ITypeSymbol rewrittenType,
1572var originalMemberType = originalMemberSymbol.GetMemberType();
1573var rewrittenMemberType = rewrittenMemberSymbol.GetMemberType();
1623private static (ITypeSymbol? rewrittenConvertedType, Conversion rewrittenConversion) GetRewrittenInfo(
1626Conversion originalConversion, ITypeSymbol originalConvertedType,
1637var convertedType = originalConversion.IsIdentity ? originalConvertedType : originalSemanticModel.Compilation.ObjectType;
1641var rewrittenConvertedType = rewrittenSemanticModel.GetTypeInfo(rewrittenExpression, cancellationToken).ConvertedType;
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\CSharp\Utilities\SpeculationAnalyzer.cs (18)
267var originalParamType = this.OriginalSemanticModel.GetDeclaredSymbol(originalParam).Type;
268var replacedParamType = this.SpeculativeSemanticModel.GetDeclaredSymbol(replacedParam).Type;
386var originalExpressionType = originalExpressionTypeInfo.Type;
387var newExpressionType = newExpressionTypeInfo.Type;
435var originalCaseType = this.OriginalSemanticModel.GetTypeInfo(previousOriginalNode, this.CancellationToken).Type;
436var newCaseType = this.SpeculativeSemanticModel.GetTypeInfo(previousReplacedNode, this.CancellationToken).Type;
561var originalExpressionType = this.OriginalSemanticModel.GetTypeInfo(originalAnonymousObjectMemberDeclarator.Expression, this.CancellationToken).Type;
562var newExpressionType = this.SpeculativeSemanticModel.GetTypeInfo(replacedAnonymousObjectMemberDeclarator.Expression, this.CancellationToken).Type;
702var originalConvertedType = this.OriginalSemanticModel.GetTypeInfo(originalIsOrAsExpression.Right).Type;
703var newConvertedType = this.SpeculativeSemanticModel.GetTypeInfo(newIsOrAsExpression.Right).Type;
841protected override bool ConversionsAreCompatible(ExpressionSyntax originalExpression, ITypeSymbol originalTargetType, ExpressionSyntax newExpression, ITypeSymbol newTargetType)
889out ITypeSymbol elementType,
931protected override bool IsReferenceConversion(Compilation compilation, ITypeSymbol sourceType, ITypeSymbol targetType)
934protected override Conversion ClassifyConversion(SemanticModel model, ExpressionSyntax expression, ITypeSymbol targetType)
937protected override Conversion ClassifyConversion(SemanticModel model, ITypeSymbol originalType, ITypeSymbol targetType)
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\CSharp\CodeGeneration\ExpressionGenerator.cs (10)
34return typedConstant.Value is ITypeSymbol typeSymbol
54ITypeSymbol? type,
63if (type.IsNullable(out var underlyingType))
75internal static ExpressionSyntax GenerateNonEnumValueExpression(ITypeSymbol? type, object? value, bool canUseFieldReference)
118private static string DetermineSuffix(ITypeSymbol? type, object value)
172private static ExpressionSyntax GenerateDoubleLiteralExpression(ITypeSymbol? type, double value, bool canUseFieldReference)
201private static ExpressionSyntax GenerateSingleLiteralExpression(ITypeSymbol? type, float value, bool canUseFieldReference)
231ITypeSymbol? type, T value, IEnumerable<KeyValuePair<T, string>> constants,
242ITypeSymbol? type, T value, IEnumerable<KeyValuePair<T, string>> constants,
278private static ExpressionSyntax? GenerateFieldReference<T>(ITypeSymbol? type, T value, IEnumerable<KeyValuePair<T, string>> constants)
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\CSharp\LanguageServices\CSharpTypeInferenceService.TypeInferrer.cs (36)
35protected override bool IsUnusableType(ITypeSymbol otherSideType)
616private static IMethodSymbol Instantiate(IMethodSymbol method, IList<ITypeSymbol> invocationTypes)
640IDictionary<ITypeParameterSymbol, ITypeSymbol> bestMap = null;
641foreach (var type in invocationTypes)
662private static Dictionary<ITypeParameterSymbol, ITypeSymbol> DetermineTypeParameterMapping(ITypeSymbol inferredType, ITypeSymbol returnType)
664var result = new Dictionary<ITypeParameterSymbol, ITypeSymbol>();
669private static void DetermineTypeParameterMapping(ITypeSymbol inferredType, ITypeSymbol returnType, Dictionary<ITypeParameterSymbol, ITypeSymbol> result)
1122return leftTypes.Select(x => x.InferredType.IsNullable(out var underlying)
1134static ITypeSymbol MakeNullable(ITypeSymbol symbol, Compilation compilation)
1448var type = this.SemanticModel.GetTypeInfo(recursivePattern).ConvertedType;
1567var elementTypesBuilder = ArrayBuilder<ITypeSymbol>.GetInstance(subPatternCount);
1592private static ImmutableArray<NullableAnnotation> GetNullableAnnotations(ImmutableArray<ITypeSymbol> elementTypes)
1763var typeArg = delegateType?.TypeArguments.Length > 0
1781private ITypeSymbol InferTypeForFirstParameterOfLambda(
1796private ITypeSymbol InferTypeForFirstParameterOfParenthesizedLambda(
1805private ITypeSymbol InferTypeForFirstParameterOfSimpleLambda(
1812private ITypeSymbol InferTypeForFirstParameterOfLambda(
1819private ITypeSymbol InferTypeForFirstParameterOfLambda(
1837var type = InferTypeForFirstParameterOfLambda(parameterName, child.AsNode());
1990var memberType = memberSymbol.GetMemberType();
2002private ITypeSymbol UnwrapTaskLike(ITypeSymbol type, bool isAsync)
2043var type = symbol.GetMemberType();
2182var type = symbol.GetSymbolType();
2271var tupleType = GetTupleType(tupleExpression);
2280private ITypeSymbol GetTupleType(
2294out ImmutableArray<ITypeSymbol> elementTypes,
2300using var _1 = ArrayBuilder<ITypeSymbol>.GetInstance(out var elementTypesBuilder);
2338ArrayBuilder<ITypeSymbol> elementTypesBuilder,
2360ArrayBuilder<ITypeSymbol> elementTypesBuilder,
2363var tupleType = GetTupleType(tuple);
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\Utilities\AbstractSpeculationAnalyzer.cs (25)
102protected abstract TConversion ClassifyConversion(SemanticModel model, TExpressionSyntax expression, ITypeSymbol targetType);
103protected abstract TConversion ClassifyConversion(SemanticModel model, ITypeSymbol originalType, ITypeSymbol targetType);
105protected abstract bool ConversionsAreCompatible(TExpressionSyntax originalExpression, ITypeSymbol originalTargetType, TExpressionSyntax newExpression, ITypeSymbol newTargetType);
106protected abstract bool IsReferenceConversion(Compilation model, ITypeSymbol sourceType, ITypeSymbol targetType);
112SemanticModel model, TForEachStatementSyntax forEach, out IMethodSymbol getEnumeratorMethod, out ITypeSymbol elementType, out ImmutableArray<ILocalSymbol> localVariables);
305private bool ImplicitConversionsAreCompatible(TExpressionSyntax originalExpression, ITypeSymbol originalTargetType, TExpressionSyntax newExpression, ITypeSymbol newTargetType)
740var previousOriginalType = this.OriginalSemanticModel.GetTypeInfo(previousOriginalNode).Type;
741var previousReplacedType = this.SpeculativeSemanticModel.GetTypeInfo(previousReplacedNode).Type;
780GetForEachSymbols(this.OriginalSemanticModel, forEachStatement, out var originalGetEnumerator, out var originalElementType, out var originalLocalVariables);
781GetForEachSymbols(this.SpeculativeSemanticModel, newForEachStatement, out var newGetEnumerator, out var newElementType, out var newLocalVariables);
826var expressionType = this.SpeculativeSemanticModel.GetTypeInfo(newForEachStatementExpression, CancellationToken).ConvertedType;
849var originalThrowExpressionType = this.OriginalSemanticModel.GetTypeInfo(originalThrowExpression).Type;
851var newThrowExpressionType = this.SpeculativeSemanticModel.GetTypeInfo(newThrowExpression).Type;
961var originalTargetType = this.OriginalSemanticModel.GetTypeInfo(originalLeft).Type;
964var newTargetType = this.SpeculativeSemanticModel.GetTypeInfo(newLeft).Type;
997var newReceiverType = newReceiver != null
1036var receiverType = semanticModel.GetTypeInfo(receiver).Type;
1196ITypeSymbol originalTargetType,
1198ITypeSymbol newTargetType,
1213var originalConvertedTypeSymbol = this.OriginalSemanticModel.GetTypeInfo(originalExpression).ConvertedType;
1219var newConvertedTypeSymbol = this.SpeculativeSemanticModel.GetTypeInfo(newExpression).ConvertedType;
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Extensions\Symbols\ITypeSymbolExtensions.cs (101)
26public static bool IsIntegralType([NotNullWhen(returnValue: true)] this ITypeSymbol? type)
29public static bool IsSignedIntegralType([NotNullWhen(returnValue: true)] this ITypeSymbol? type)
32public static bool CanAddNullCheck([NotNullWhen(returnValue: true)] this ITypeSymbol? type)
43public static ImmutableArray<INamedTypeSymbol> GetAllInterfacesIncludingThis(this ITypeSymbol type)
51public static bool IsAbstractClass([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
54public static bool IsSystemVoid([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
57public static bool IsNullable([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
60public static bool IsNonNullableValueType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
64[NotNullWhen(true)] this ITypeSymbol? symbol,
65[NotNullWhen(true)] out ITypeSymbol? underlyingType)
77public static bool IsModuleType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
80public static bool IsInterfaceType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
83public static bool IsDelegateType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
86public static bool IsFunctionPointerType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
89public static bool IsStructType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
96this ITypeSymbol type,
110public static IEnumerable<ITypeSymbol> GetBaseTypesAndThis(this ITypeSymbol? type)
112var current = type;
120public static IEnumerable<INamedTypeSymbol> GetBaseTypes(this ITypeSymbol? type)
130public static IEnumerable<ITypeSymbol> GetContainingTypesAndThis(this ITypeSymbol? type)
132var current = type;
140public static IEnumerable<INamedTypeSymbol> GetContainingTypes(this ITypeSymbol type)
153this ITypeSymbol type, ITypeSymbol baseType, bool includeInterfaces)
166this ITypeSymbol type, ITypeSymbol baseType)
174this ITypeSymbol type, ITypeSymbol baseType)
176var originalBaseType = baseType.OriginalDefinition;
184IEnumerable<ITypeSymbol> baseTypes = (baseType.TypeKind == TypeKind.Interface) ? type.AllInterfaces : type.GetBaseTypes();
191this ITypeSymbol type, ITypeSymbol baseType)
193var originalBaseType = baseType.OriginalDefinition;
213this ITypeSymbol type, ITypeSymbol interfaceType)
215var originalInterfaceType = interfaceType.OriginalDefinition;
220this ITypeSymbol type, ITypeSymbol interfaceType)
225public static bool IsAttribute(this ITypeSymbol symbol)
243public static bool IsFormattableStringOrIFormattable([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
252this ITypeSymbol typeSymbol, bool allowDelegateAndEnumConstraints = false)
280public static bool IsNumericType([NotNullWhen(returnValue: true)] this ITypeSymbol? type)
306public static Accessibility DetermineMinimalAccessibility(this ITypeSymbol typeSymbol)
309public static bool ContainsAnonymousType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
325foreach (var typeArg in type.GetAllTypeArguments())
334public static string CreateParameterName(this ITypeSymbol type, bool capitalize = false)
355private static string GetParameterName(ITypeSymbol? type)
368public static bool IsSpecialType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
399public static bool CanSupportCollectionInitializer(this ITypeSymbol typeSymbol, ISymbol within)
410public static INamedTypeSymbol? GetDelegateType(this ITypeSymbol? typeSymbol, Compilation compilation)
417var typeArgument = ((INamedTypeSymbol)typeSymbol).TypeArguments[0];
430public static IEnumerable<T> GetAccessibleMembersInBaseTypes<T>(this ITypeSymbol containingType, ISymbol within) where T : class, ISymbol
439public static ImmutableArray<T> GetAccessibleMembersInThisAndBaseTypes<T>(this ITypeSymbol? containingType, ISymbol within) where T : class, ISymbol
449public static ImmutableArray<T> GetAccessibleMembersInThisAndBaseTypes<T>(this ITypeSymbol? containingType, string memberName, ISymbol within) where T : class, ISymbol
459public static bool? AreMoreSpecificThan(this IList<ITypeSymbol> t1, IList<ITypeSymbol> t2)
494public static IEnumerable<T> SelectAccessibleMembers<T>(this IEnumerable<ITypeSymbol>? types, ISymbol within) where T : class, ISymbol
504private static IEnumerable<T> SelectAccessibleMembers<T>(this IEnumerable<ITypeSymbol>? types, string memberName, ISymbol within) where T : class, ISymbol
514private static bool? IsMoreSpecificThan(this ITypeSymbol t1, ITypeSymbol t2)
592public static bool IsOrDerivesFromExceptionType([NotNullWhen(returnValue: true)] this ITypeSymbol? type, Compilation compilation)
599foreach (var baseType in type.GetBaseTypesAndThis())
610foreach (var constraint in ((ITypeParameterSymbol)type).ConstraintTypes)
625public static bool IsEnumType([NotNullWhen(true)] this ITypeSymbol? type)
628public static bool IsEnumType([NotNullWhen(true)] this ITypeSymbol? type, [NotNullWhen(true)] out INamedTypeSymbol? enumType)
640public static bool? IsMutableValueType(this ITypeSymbol type)
642if (type.IsNullable(out var underlyingType))
721static bool IsWellKnownImmutableValueType(ITypeSymbol type)
754public static bool IsDisposable([NotNullWhen(returnValue: true)] this ITypeSymbol? type, [NotNullWhen(returnValue: true)] ITypeSymbol? iDisposableType)
759public static ITypeSymbol WithNullableAnnotationFrom(this ITypeSymbol type, ITypeSymbol symbolForNullableAnnotation)
763public static ITypeSymbol? RemoveNullableIfPresent(this ITypeSymbol? symbol)
765if (symbol.IsNullable(out var underlyingType))
773public static bool IsSpanOrReadOnlySpan([NotNullWhen(true)] this ITypeSymbol? type)
776public static bool IsSpan([NotNullWhen(true)] this ITypeSymbol? type)
792public static bool IsInlineArray([NotNullWhen(true)] this ITypeSymbol? type)
797public static ITypeSymbol? RemoveUnavailableTypeParameters(
798this ITypeSymbol? type,
806private static ITypeSymbol? RemoveUnavailableTypeParameters(
807this ITypeSymbol? type,
815public static ITypeSymbol? RemoveAnonymousTypes(
816this ITypeSymbol? type,
823public static ITypeSymbol? RemoveUnnamedErrorTypes(
824this ITypeSymbol? type,
831this ITypeSymbol? type, ArrayBuilder<ITypeParameterSymbol> result)
837this ITypeSymbol? type, ArrayBuilder<ITypeParameterSymbol> result)
843this ITypeSymbol? type, ArrayBuilder<ITypeParameterSymbol> result, bool onlyMethodTypeParameters)
852public static IList<ITypeParameterSymbol> GetReferencedTypeParameters(this ITypeSymbol? type)
860public static ITypeSymbol? SubstituteTypes<TType1, TType2>(
861this ITypeSymbol? type,
864where TType1 : ITypeSymbol
865where TType2 : ITypeSymbol
871public static ITypeSymbol? SubstituteTypes<TType1, TType2>(
872this ITypeSymbol? type,
875where TType1 : ITypeSymbol
876where TType2 : ITypeSymbol
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\Utilities\AbstractSpeculationAnalyzer.cs (25)
102protected abstract TConversion ClassifyConversion(SemanticModel model, TExpressionSyntax expression, ITypeSymbol targetType);
103protected abstract TConversion ClassifyConversion(SemanticModel model, ITypeSymbol originalType, ITypeSymbol targetType);
105protected abstract bool ConversionsAreCompatible(TExpressionSyntax originalExpression, ITypeSymbol originalTargetType, TExpressionSyntax newExpression, ITypeSymbol newTargetType);
106protected abstract bool IsReferenceConversion(Compilation model, ITypeSymbol sourceType, ITypeSymbol targetType);
112SemanticModel model, TForEachStatementSyntax forEach, out IMethodSymbol getEnumeratorMethod, out ITypeSymbol elementType, out ImmutableArray<ILocalSymbol> localVariables);
305private bool ImplicitConversionsAreCompatible(TExpressionSyntax originalExpression, ITypeSymbol originalTargetType, TExpressionSyntax newExpression, ITypeSymbol newTargetType)
740var previousOriginalType = this.OriginalSemanticModel.GetTypeInfo(previousOriginalNode).Type;
741var previousReplacedType = this.SpeculativeSemanticModel.GetTypeInfo(previousReplacedNode).Type;
780GetForEachSymbols(this.OriginalSemanticModel, forEachStatement, out var originalGetEnumerator, out var originalElementType, out var originalLocalVariables);
781GetForEachSymbols(this.SpeculativeSemanticModel, newForEachStatement, out var newGetEnumerator, out var newElementType, out var newLocalVariables);
826var expressionType = this.SpeculativeSemanticModel.GetTypeInfo(newForEachStatementExpression, CancellationToken).ConvertedType;
849var originalThrowExpressionType = this.OriginalSemanticModel.GetTypeInfo(originalThrowExpression).Type;
851var newThrowExpressionType = this.SpeculativeSemanticModel.GetTypeInfo(newThrowExpression).Type;
961var originalTargetType = this.OriginalSemanticModel.GetTypeInfo(originalLeft).Type;
964var newTargetType = this.SpeculativeSemanticModel.GetTypeInfo(newLeft).Type;
997var newReceiverType = newReceiver != null
1036var receiverType = semanticModel.GetTypeInfo(receiver).Type;
1196ITypeSymbol originalTargetType,
1198ITypeSymbol newTargetType,
1213var originalConvertedTypeSymbol = this.OriginalSemanticModel.GetTypeInfo(originalExpression).ConvertedType;
1219var newConvertedTypeSymbol = this.SpeculativeSemanticModel.GetTypeInfo(newExpression).ConvertedType;
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Extensions\Symbols\ITypeSymbolExtensions.cs (101)
26public static bool IsIntegralType([NotNullWhen(returnValue: true)] this ITypeSymbol? type)
29public static bool IsSignedIntegralType([NotNullWhen(returnValue: true)] this ITypeSymbol? type)
32public static bool CanAddNullCheck([NotNullWhen(returnValue: true)] this ITypeSymbol? type)
43public static ImmutableArray<INamedTypeSymbol> GetAllInterfacesIncludingThis(this ITypeSymbol type)
51public static bool IsAbstractClass([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
54public static bool IsSystemVoid([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
57public static bool IsNullable([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
60public static bool IsNonNullableValueType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
64[NotNullWhen(true)] this ITypeSymbol? symbol,
65[NotNullWhen(true)] out ITypeSymbol? underlyingType)
77public static bool IsModuleType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
80public static bool IsInterfaceType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
83public static bool IsDelegateType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
86public static bool IsFunctionPointerType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
89public static bool IsStructType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
96this ITypeSymbol type,
110public static IEnumerable<ITypeSymbol> GetBaseTypesAndThis(this ITypeSymbol? type)
112var current = type;
120public static IEnumerable<INamedTypeSymbol> GetBaseTypes(this ITypeSymbol? type)
130public static IEnumerable<ITypeSymbol> GetContainingTypesAndThis(this ITypeSymbol? type)
132var current = type;
140public static IEnumerable<INamedTypeSymbol> GetContainingTypes(this ITypeSymbol type)
153this ITypeSymbol type, ITypeSymbol baseType, bool includeInterfaces)
166this ITypeSymbol type, ITypeSymbol baseType)
174this ITypeSymbol type, ITypeSymbol baseType)
176var originalBaseType = baseType.OriginalDefinition;
184IEnumerable<ITypeSymbol> baseTypes = (baseType.TypeKind == TypeKind.Interface) ? type.AllInterfaces : type.GetBaseTypes();
191this ITypeSymbol type, ITypeSymbol baseType)
193var originalBaseType = baseType.OriginalDefinition;
213this ITypeSymbol type, ITypeSymbol interfaceType)
215var originalInterfaceType = interfaceType.OriginalDefinition;
220this ITypeSymbol type, ITypeSymbol interfaceType)
225public static bool IsAttribute(this ITypeSymbol symbol)
243public static bool IsFormattableStringOrIFormattable([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
252this ITypeSymbol typeSymbol, bool allowDelegateAndEnumConstraints = false)
280public static bool IsNumericType([NotNullWhen(returnValue: true)] this ITypeSymbol? type)
306public static Accessibility DetermineMinimalAccessibility(this ITypeSymbol typeSymbol)
309public static bool ContainsAnonymousType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
325foreach (var typeArg in type.GetAllTypeArguments())
334public static string CreateParameterName(this ITypeSymbol type, bool capitalize = false)
355private static string GetParameterName(ITypeSymbol? type)
368public static bool IsSpecialType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
399public static bool CanSupportCollectionInitializer(this ITypeSymbol typeSymbol, ISymbol within)
410public static INamedTypeSymbol? GetDelegateType(this ITypeSymbol? typeSymbol, Compilation compilation)
417var typeArgument = ((INamedTypeSymbol)typeSymbol).TypeArguments[0];
430public static IEnumerable<T> GetAccessibleMembersInBaseTypes<T>(this ITypeSymbol containingType, ISymbol within) where T : class, ISymbol
439public static ImmutableArray<T> GetAccessibleMembersInThisAndBaseTypes<T>(this ITypeSymbol? containingType, ISymbol within) where T : class, ISymbol
449public static ImmutableArray<T> GetAccessibleMembersInThisAndBaseTypes<T>(this ITypeSymbol? containingType, string memberName, ISymbol within) where T : class, ISymbol
459public static bool? AreMoreSpecificThan(this IList<ITypeSymbol> t1, IList<ITypeSymbol> t2)
494public static IEnumerable<T> SelectAccessibleMembers<T>(this IEnumerable<ITypeSymbol>? types, ISymbol within) where T : class, ISymbol
504private static IEnumerable<T> SelectAccessibleMembers<T>(this IEnumerable<ITypeSymbol>? types, string memberName, ISymbol within) where T : class, ISymbol
514private static bool? IsMoreSpecificThan(this ITypeSymbol t1, ITypeSymbol t2)
592public static bool IsOrDerivesFromExceptionType([NotNullWhen(returnValue: true)] this ITypeSymbol? type, Compilation compilation)
599foreach (var baseType in type.GetBaseTypesAndThis())
610foreach (var constraint in ((ITypeParameterSymbol)type).ConstraintTypes)
625public static bool IsEnumType([NotNullWhen(true)] this ITypeSymbol? type)
628public static bool IsEnumType([NotNullWhen(true)] this ITypeSymbol? type, [NotNullWhen(true)] out INamedTypeSymbol? enumType)
640public static bool? IsMutableValueType(this ITypeSymbol type)
642if (type.IsNullable(out var underlyingType))
721static bool IsWellKnownImmutableValueType(ITypeSymbol type)
754public static bool IsDisposable([NotNullWhen(returnValue: true)] this ITypeSymbol? type, [NotNullWhen(returnValue: true)] ITypeSymbol? iDisposableType)
759public static ITypeSymbol WithNullableAnnotationFrom(this ITypeSymbol type, ITypeSymbol symbolForNullableAnnotation)
763public static ITypeSymbol? RemoveNullableIfPresent(this ITypeSymbol? symbol)
765if (symbol.IsNullable(out var underlyingType))
773public static bool IsSpanOrReadOnlySpan([NotNullWhen(true)] this ITypeSymbol? type)
776public static bool IsSpan([NotNullWhen(true)] this ITypeSymbol? type)
792public static bool IsInlineArray([NotNullWhen(true)] this ITypeSymbol? type)
797public static ITypeSymbol? RemoveUnavailableTypeParameters(
798this ITypeSymbol? type,
806private static ITypeSymbol? RemoveUnavailableTypeParameters(
807this ITypeSymbol? type,
815public static ITypeSymbol? RemoveAnonymousTypes(
816this ITypeSymbol? type,
823public static ITypeSymbol? RemoveUnnamedErrorTypes(
824this ITypeSymbol? type,
831this ITypeSymbol? type, ArrayBuilder<ITypeParameterSymbol> result)
837this ITypeSymbol? type, ArrayBuilder<ITypeParameterSymbol> result)
843this ITypeSymbol? type, ArrayBuilder<ITypeParameterSymbol> result, bool onlyMethodTypeParameters)
852public static IList<ITypeParameterSymbol> GetReferencedTypeParameters(this ITypeSymbol? type)
860public static ITypeSymbol? SubstituteTypes<TType1, TType2>(
861this ITypeSymbol? type,
864where TType1 : ITypeSymbol
865where TType2 : ITypeSymbol
871public static ITypeSymbol? SubstituteTypes<TType1, TType2>(
872this ITypeSymbol? type,
875where TType1 : ITypeSymbol
876where TType2 : ITypeSymbol
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\Core\CodeGeneration\CodeGenerationSymbolFactory.cs (18)
30DeclarationModifiers modifiers, ITypeSymbol type,
47ITypeSymbol type,
79ITypeSymbol type, RefKind refKind, ImmutableArray<IPropertySymbol> explicitInterfaceImplementations, string name,
106ITypeSymbol type, string name,
152ITypeSymbol? returnType,
174ITypeSymbol? returnType,
195ITypeSymbol returnType,
220ITypeSymbol toType,
248ITypeSymbol toType,
264public static IParameterSymbol CreateParameterSymbol(ITypeSymbol type, string name)
267public static IParameterSymbol CreateParameterSymbol(RefKind refKind, ITypeSymbol type, string name)
277ImmutableArray<AttributeData> attributes, RefKind refKind, bool isParams, ITypeSymbol type, string name, bool isOptional = false, bool hasDefaultValue = false, object? defaultValue = null)
290ITypeSymbol? type = null,
331ImmutableArray<ITypeSymbol> constraintTypes,
347public static IPointerTypeSymbol CreatePointerTypeSymbol(ITypeSymbol pointedAtType)
353public static IArrayTypeSymbol CreateArrayTypeSymbol(ITypeSymbol elementType, int rank = 1, NullableAnnotation nullableAnnotation = NullableAnnotation.None)
463ITypeSymbol returnType,
520ITypeSymbol? returnType = null,
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\Core\CodeGeneration\Symbols\CodeGenerationArrayTypeSymbol.cs (2)
10internal sealed class CodeGenerationArrayTypeSymbol(ITypeSymbol elementType, int rank, NullableAnnotation nullableAnnotation) : CodeGenerationTypeSymbol(null, null, default, Accessibility.NotApplicable, default, string.Empty, SpecialType.None, nullableAnnotation), IArrayTypeSymbol
12public ITypeSymbol ElementType { get; } = elementType;
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\Core\CodeGeneration\Symbols\CodeGenerationConversionSymbol.cs (1)
15ITypeSymbol toType,
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\Core\CodeGeneration\Symbols\CodeGenerationOperatorSymbol.cs (1)
15ITypeSymbol returnType,