src\RoslynAnalyzers\Utilities\Compiler\Extensions\ITypeSymbolExtensions.cs (28)
19[NotNullWhen(returnValue: true)] this ITypeSymbol? fromSymbol,
20[NotNullWhen(returnValue: true)] ITypeSymbol? toSymbol,
25public static bool IsPrimitiveType(this ITypeSymbol type)
46public static bool Inherits([NotNullWhen(returnValue: true)] this ITypeSymbol? type, [NotNullWhen(returnValue: true)] ITypeSymbol? possibleBase)
71public static IEnumerable<INamedTypeSymbol> GetBaseTypes(this ITypeSymbol type, Func<INamedTypeSymbol, bool>? takeWhilePredicate = null)
82public static IEnumerable<ITypeSymbol> GetBaseTypesAndThis(this ITypeSymbol type)
84ITypeSymbol current = type;
92public static bool DerivesFrom([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol, [NotNullWhen(returnValue: true)] ITypeSymbol? candidateBaseType, bool baseTypesOnly = false, bool checkTypeParameterConstraints = true)
101var allInterfaces = symbol.AllInterfaces.OfType<ITypeSymbol>();
117foreach (var constraintType in typeParameterSymbol.ConstraintTypes)
143public static bool IsDisposable(this ITypeSymbol type,
168static bool IsInterfaceOrImplementsInterface(ITypeSymbol type, INamedTypeSymbol? interfaceType)
278public static bool IsAttribute(this ITypeSymbol symbol)
296public static bool HasValueCopySemantics(this ITypeSymbol typeSymbol)
300public static bool CanHoldNullValue([NotNullWhen(returnValue: true)] this ITypeSymbol? typeSymbol)
306public static bool IsNonNullableValueType([NotNullWhen(returnValue: true)] this ITypeSymbol? typeSymbol)
309public static bool IsNullableValueType([NotNullWhen(returnValue: true)] this ITypeSymbol? typeSymbol)
312public static bool IsReferenceTypeOrNullableValueType([NotNullWhen(returnValue: true)] this ITypeSymbol? typeSymbol)
315public static bool IsNullableOfBoolean([NotNullWhen(returnValue: true)] this ITypeSymbol? typeSymbol)
318public static ITypeSymbol? GetNullableValueTypeUnderlyingType(this ITypeSymbol? typeSymbol)
322public static ITypeSymbol? GetUnderlyingValueTupleTypeOrThis(this ITypeSymbol? typeSymbol)
335public static bool HasAnyCollectionCountProperty([NotNullWhen(returnValue: true)] this ITypeSymbol? invocationTarget, WellKnownTypeProvider wellKnownTypeProvider)
382bool isAnySupportedCollectionType(ITypeSymbol type)
src\RoslynAnalyzers\Utilities\FlowAnalysis\FlowAnalysis\Analysis\PointsToAnalysis\PointsToAnalysis.PointsToDataFlowOperationVisitor.cs (8)
169protected override PointsToAbstractValue GetAbstractDefaultValue(ITypeSymbol? type) => !PointsToAnalysis.ShouldBeTracked(type, IsDisposable) ? PointsToAbstractValue.NoLocation : PointsToAbstractValue.NullLocation;
437ITypeSymbol targetType,
443Func<ITypeSymbol?, bool> isDisposable,
503ITypeSymbol targetType,
738protected override void SetAbstractValueForArrayElementInitializer(IArrayCreationOperation arrayCreation, ImmutableArray<AbstractIndex> indices, ITypeSymbol elementType, IOperation initializer, PointsToAbstractValue value)
1050private NullAbstractValue GetNullStateBasedOnInstanceOrReferenceValue(IOperation? referenceOrInstance, ITypeSymbol? operationType, NullAbstractValue defaultValue)
1251public 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)
135ITypeSymbol? type = operation.Type;
316var type = symbol.GetMemberOrLocalOrParameterType();
346var underlyingValueTupleType = tupleType.GetUnderlyingValueTupleTypeOrThis()!;
396public bool TryCreateForArrayElementInitializer(IArrayCreationOperation arrayCreation, ImmutableArray<AbstractIndex> indices, ITypeSymbol elementType, [NotNullWhen(returnValue: true)] out AnalysisEntity? analysisEntity)
412private AnalysisEntity GetOrCreateForFlowCapture(CaptureId captureId, ITypeSymbol? type, IOperation flowCaptureOrReference, bool isLValueFlowCapture)
439ITypeSymbol type, IOperation? instance, [NotNullWhen(returnValue: true)] out AnalysisEntity? analysisEntity)
553private AnalysisEntity Create(ISymbol? symbol, ImmutableArray<AbstractIndex> indices, ITypeSymbol type, PointsToAbstractValue? instanceLocation, AnalysisEntity? parent, AnalysisEntity? entityForInstanceLocation)
src\Analyzers\Core\Analyzers\RemoveUnusedParametersAndValues\AbstractRemoveUnusedParametersAndValuesDiagnosticAnalyzer.SymbolStartAnalyzer.cs (1)
292ITypeSymbol containingType,
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\Extensions\ITypeSymbolExtensions.cs (100)
23public static bool IsIntegralType([NotNullWhen(returnValue: true)] this ITypeSymbol? type)
26public static bool IsSignedIntegralType([NotNullWhen(returnValue: true)] this ITypeSymbol? type)
29public static bool CanAddNullCheck([NotNullWhen(returnValue: true)] this ITypeSymbol? type)
40public static IList<INamedTypeSymbol> GetAllInterfacesIncludingThis(this ITypeSymbol type)
56public static bool IsAbstractClass([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
59public static bool IsSystemVoid([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
62public static bool IsNullable([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
65public static bool IsNonNullableValueType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
69[NotNullWhen(true)] this ITypeSymbol? symbol,
70[NotNullWhen(true)] out ITypeSymbol? underlyingType)
82public static bool IsModuleType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
85public static bool IsInterfaceType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
88public static bool IsDelegateType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
91public static bool IsFunctionPointerType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
94public static bool IsStructType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
101this ITypeSymbol type,
115public static IEnumerable<ITypeSymbol> GetBaseTypesAndThis(this ITypeSymbol? type)
117var current = type;
125public static IEnumerable<INamedTypeSymbol> GetBaseTypes(this ITypeSymbol? type)
135public static IEnumerable<ITypeSymbol> GetContainingTypesAndThis(this ITypeSymbol? type)
137var current = type;
145public static IEnumerable<INamedTypeSymbol> GetContainingTypes(this ITypeSymbol type)
158this ITypeSymbol type, ITypeSymbol baseType, bool includeInterfaces)
171this ITypeSymbol type, ITypeSymbol baseType)
179this ITypeSymbol type, ITypeSymbol baseType)
181var originalBaseType = baseType.OriginalDefinition;
189IEnumerable<ITypeSymbol> baseTypes = (baseType.TypeKind == TypeKind.Interface) ? type.AllInterfaces : type.GetBaseTypes();
196this ITypeSymbol type, ITypeSymbol baseType)
198var originalBaseType = baseType.OriginalDefinition;
218this ITypeSymbol type, ITypeSymbol interfaceType)
220var originalInterfaceType = interfaceType.OriginalDefinition;
225this ITypeSymbol type, ITypeSymbol interfaceType)
230public static bool IsAttribute(this ITypeSymbol symbol)
248public static bool IsFormattableStringOrIFormattable([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
257this ITypeSymbol typeSymbol, bool allowDelegateAndEnumConstraints = false)
285public static bool IsNumericType([NotNullWhen(returnValue: true)] this ITypeSymbol? type)
311public static Accessibility DetermineMinimalAccessibility(this ITypeSymbol typeSymbol)
314public static bool ContainsAnonymousType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
330foreach (var typeArg in type.GetAllTypeArguments())
339public static string CreateParameterName(this ITypeSymbol type, bool capitalize = false)
360private static string GetParameterName(ITypeSymbol? type)
373public static bool IsSpecialType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
404public static bool CanSupportCollectionInitializer(this ITypeSymbol typeSymbol, ISymbol within)
415public static INamedTypeSymbol? GetDelegateType(this ITypeSymbol? typeSymbol, Compilation compilation)
422var typeArgument = ((INamedTypeSymbol)typeSymbol).TypeArguments[0];
435public static IEnumerable<T> GetAccessibleMembersInBaseTypes<T>(this ITypeSymbol containingType, ISymbol within) where T : class, ISymbol
444public static ImmutableArray<T> GetAccessibleMembersInThisAndBaseTypes<T>(this ITypeSymbol? containingType, ISymbol within) where T : class, ISymbol
454public static ImmutableArray<T> GetAccessibleMembersInThisAndBaseTypes<T>(this ITypeSymbol? containingType, string memberName, ISymbol within) where T : class, ISymbol
464public static bool? AreMoreSpecificThan(this IList<ITypeSymbol> t1, IList<ITypeSymbol> t2)
499public static IEnumerable<T> SelectAccessibleMembers<T>(this IEnumerable<ITypeSymbol>? types, ISymbol within) where T : class, ISymbol
509private static IEnumerable<T> SelectAccessibleMembers<T>(this IEnumerable<ITypeSymbol>? types, string memberName, ISymbol within) where T : class, ISymbol
519private static bool? IsMoreSpecificThan(this ITypeSymbol t1, ITypeSymbol t2)
598public static bool IsOrDerivesFromExceptionType([NotNullWhen(returnValue: true)] this ITypeSymbol? type, Compilation compilation)
605foreach (var baseType in type.GetBaseTypesAndThis())
616foreach (var constraint in ((ITypeParameterSymbol)type).ConstraintTypes)
631public static bool IsEnumType([NotNullWhen(true)] this ITypeSymbol? type)
634public static bool IsEnumType([NotNullWhen(true)] this ITypeSymbol? type, [NotNullWhen(true)] out INamedTypeSymbol? enumType)
646public static bool? IsMutableValueType(this ITypeSymbol type)
648if (type.IsNullable(out var underlyingType))
725public static bool IsDisposable([NotNullWhen(returnValue: true)] this ITypeSymbol? type, [NotNullWhen(returnValue: true)] ITypeSymbol? iDisposableType)
730public static ITypeSymbol WithNullableAnnotationFrom(this ITypeSymbol type, ITypeSymbol symbolForNullableAnnotation)
734public static ITypeSymbol? RemoveNullableIfPresent(this ITypeSymbol? symbol)
736if (symbol.IsNullable(out var underlyingType))
744public static bool IsSpanOrReadOnlySpan([NotNullWhen(true)] this ITypeSymbol? type)
747public static bool IsSpan([NotNullWhen(true)] this ITypeSymbol? type)
763public static bool IsInlineArray([NotNullWhen(true)] this ITypeSymbol? type)
768public static ITypeSymbol? RemoveUnavailableTypeParameters(
769this ITypeSymbol? type,
777private static ITypeSymbol? RemoveUnavailableTypeParameters(
778this ITypeSymbol? type,
786public static ITypeSymbol? RemoveAnonymousTypes(
787this ITypeSymbol? type,
794public static ITypeSymbol? RemoveUnnamedErrorTypes(
795this ITypeSymbol? type,
802this ITypeSymbol? type, ArrayBuilder<ITypeParameterSymbol> result)
808this ITypeSymbol? type, ArrayBuilder<ITypeParameterSymbol> result)
814this ITypeSymbol? type, ArrayBuilder<ITypeParameterSymbol> result, bool onlyMethodTypeParameters)
823public static IList<ITypeParameterSymbol> GetReferencedTypeParameters(this ITypeSymbol? type)
831public static ITypeSymbol? SubstituteTypes<TType1, TType2>(
832this ITypeSymbol? type,
835where TType1 : ITypeSymbol
836where TType2 : ITypeSymbol
842public static ITypeSymbol? SubstituteTypes<TType1, TType2>(
843this ITypeSymbol? type,
846where TType1 : ITypeSymbol
847where TType2 : ITypeSymbol
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\Utilities\AbstractSpeculationAnalyzer.cs (25)
104protected abstract TConversion ClassifyConversion(SemanticModel model, TExpressionSyntax expression, ITypeSymbol targetType);
105protected abstract TConversion ClassifyConversion(SemanticModel model, ITypeSymbol originalType, ITypeSymbol targetType);
107protected abstract bool ConversionsAreCompatible(TExpressionSyntax originalExpression, ITypeSymbol originalTargetType, TExpressionSyntax newExpression, ITypeSymbol newTargetType);
108protected abstract bool IsReferenceConversion(Compilation model, ITypeSymbol sourceType, ITypeSymbol targetType);
114SemanticModel model, TForEachStatementSyntax forEach, out IMethodSymbol getEnumeratorMethod, out ITypeSymbol elementType, out ImmutableArray<ILocalSymbol> localVariables);
304private bool ImplicitConversionsAreCompatible(TExpressionSyntax originalExpression, ITypeSymbol originalTargetType, TExpressionSyntax newExpression, ITypeSymbol newTargetType)
739var previousOriginalType = this.OriginalSemanticModel.GetTypeInfo(previousOriginalNode).Type;
740var previousReplacedType = this.SpeculativeSemanticModel.GetTypeInfo(previousReplacedNode).Type;
779GetForEachSymbols(this.OriginalSemanticModel, forEachStatement, out var originalGetEnumerator, out var originalElementType, out var originalLocalVariables);
780GetForEachSymbols(this.SpeculativeSemanticModel, newForEachStatement, out var newGetEnumerator, out var newElementType, out var newLocalVariables);
825var expressionType = this.SpeculativeSemanticModel.GetTypeInfo(newForEachStatementExpression, CancellationToken).ConvertedType;
848var originalThrowExpressionType = this.OriginalSemanticModel.GetTypeInfo(originalThrowExpression).Type;
850var newThrowExpressionType = this.SpeculativeSemanticModel.GetTypeInfo(newThrowExpression).Type;
960var originalTargetType = this.OriginalSemanticModel.GetTypeInfo(originalLeft).Type;
963var newTargetType = this.SpeculativeSemanticModel.GetTypeInfo(newLeft).Type;
996var newReceiverType = newReceiver != null
1035var receiverType = semanticModel.GetTypeInfo(receiver).Type;
1195ITypeSymbol originalTargetType,
1197ITypeSymbol newTargetType,
1212var originalConvertedTypeSymbol = this.OriginalSemanticModel.GetTypeInfo(originalExpression).ConvertedType;
1218var newConvertedTypeSymbol = this.SpeculativeSemanticModel.GetTypeInfo(newExpression).ConvertedType;
src\Analyzers\Core\CodeFixes\AddExplicitCast\AbstractAddExplicitCastCodeFixProvider.cs (11)
30protected abstract TExpressionSyntax Cast(TExpressionSyntax expression, ITypeSymbol type);
48protected ImmutableArray<(TExpressionSyntax node, ITypeSymbol type)> GetPotentialTargetTypes(
52using var _ = ArrayBuilder<(TExpressionSyntax node, ITypeSymbol type)>.GetInstance(out var candidates);
63ArrayBuilder<(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)
46protected abstract ITypeSymbol GetArgumentType(SyntaxNode argumentNode, SemanticModel semanticModel, CancellationToken cancellationToken);
401private async Task<(ITypeSymbol, RefKind)> GetArgumentTypeAndRefKindAsync(Document invocationDocument, TArgumentSyntax argument, CancellationToken cancellationToken)
405var argumentType = GetArgumentType(argument, semanticModel, cancellationToken);
536Compilation compilation, TypeInfo argumentTypeInfo, ITypeSymbol parameterType,
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\Core\CodeGeneration\CodeGenerationSymbolFactory.cs (18)
35DeclarationModifiers modifiers, ITypeSymbol type,
52ITypeSymbol type,
84ITypeSymbol type, RefKind refKind, ImmutableArray<IPropertySymbol> explicitInterfaceImplementations, string name,
111ITypeSymbol type, string name,
157ITypeSymbol? returnType,
179ITypeSymbol? returnType,
200ITypeSymbol returnType,
225ITypeSymbol toType,
253ITypeSymbol toType,
269public static IParameterSymbol CreateParameterSymbol(ITypeSymbol type, string name)
272public static IParameterSymbol CreateParameterSymbol(RefKind refKind, ITypeSymbol type, string name)
282ImmutableArray<AttributeData> attributes, RefKind refKind, bool isParams, ITypeSymbol type, string name, bool isOptional = false, bool hasDefaultValue = false, object? defaultValue = null)
295ITypeSymbol? type = null,
336ImmutableArray<ITypeSymbol> constraintTypes,
352public static IPointerTypeSymbol CreatePointerTypeSymbol(ITypeSymbol pointedAtType)
358public static IArrayTypeSymbol CreateArrayTypeSymbol(ITypeSymbol elementType, int rank = 1, NullableAnnotation nullableAnnotation = NullableAnnotation.None)
468ITypeSymbol returnType,
525ITypeSymbol? 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)
20ITypeSymbol toType,
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\Core\CodeGeneration\Symbols\CodeGenerationOperatorSymbol.cs (1)
20ITypeSymbol returnType,
src\Analyzers\CSharp\CodeFixes\GenerateMethod\GenerateDeconstructMethodCodeFixProvider.cs (1)
57ITypeSymbol? type;
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\CSharp\CodeGeneration\ExpressionGenerator.cs (9)
34return typedConstant.Value is ITypeSymbol typeSymbol
54ITypeSymbol? type,
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 (31)
34protected override bool IsUnusableType(ITypeSymbol otherSideType)
615private static IMethodSymbol Instantiate(IMethodSymbol method, IList<ITypeSymbol> invocationTypes)
639IDictionary<ITypeParameterSymbol, ITypeSymbol> bestMap = null;
640foreach (var type in invocationTypes)
661private static Dictionary<ITypeParameterSymbol, ITypeSymbol> DetermineTypeParameterMapping(ITypeSymbol inferredType, ITypeSymbol returnType)
663var result = new Dictionary<ITypeParameterSymbol, ITypeSymbol>();
668private static void DetermineTypeParameterMapping(ITypeSymbol inferredType, ITypeSymbol returnType, Dictionary<ITypeParameterSymbol, ITypeSymbol> result)
1133static ITypeSymbol MakeNullable(ITypeSymbol symbol, Compilation compilation)
1447var type = this.SemanticModel.GetTypeInfo(recursivePattern).ConvertedType;
1566var elementTypesBuilder = ArrayBuilder<ITypeSymbol>.GetInstance(subPatternCount);
1591private static ImmutableArray<NullableAnnotation> GetNullableAnnotations(ImmutableArray<ITypeSymbol> elementTypes)
1780private ITypeSymbol InferTypeForFirstParameterOfLambda(
1795private ITypeSymbol InferTypeForFirstParameterOfParenthesizedLambda(
1804private ITypeSymbol InferTypeForFirstParameterOfSimpleLambda(
1811private ITypeSymbol InferTypeForFirstParameterOfLambda(
1818private ITypeSymbol InferTypeForFirstParameterOfLambda(
1836var type = InferTypeForFirstParameterOfLambda(parameterName, child.AsNode());
2001private ITypeSymbol UnwrapTaskLike(ITypeSymbol type, bool isAsync)
2270var tupleType = GetTupleType(tupleExpression);
2279private ITypeSymbol GetTupleType(
2293out ImmutableArray<ITypeSymbol> elementTypes,
2299using var _1 = ArrayBuilder<ITypeSymbol>.GetInstance(out var elementTypesBuilder);
2337ArrayBuilder<ITypeSymbol> elementTypesBuilder,
2359ArrayBuilder<ITypeSymbol> elementTypesBuilder,
2362var 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;
Recommendations\CSharpRecommendationServiceRunner.cs (14)
51public override bool TryGetExplicitTypeOfLambdaParameter(SyntaxNode lambdaSyntax, int ordinalInLambda, [NotNullWhen(true)] out ITypeSymbol? explicitLambdaParameterType)
542if (name.ShouldNameExpressionBeTreatedAsExpressionInsteadOfType(_context.SemanticModel, out var nameBinding, out var container))
600var container = _context.SemanticModel.GetTypeInfo(identifier, _cancellationToken).Type;
650var container = _context.SemanticModel.GetTypeInfo(expression, _cancellationToken).Type;
660var container = _context.SemanticModel.GetTypeInfo(expression, _cancellationToken).Type;
675var container = _context.SemanticModel.GetTypeInfo(expression, _cancellationToken).Type;
691ITypeSymbol? containerType,
756private RecommendedSymbols GetSymbolsOffOfBoundExpressionWorker(SymbolInfo leftHandBinding, ExpressionSyntax originalExpression, ExpressionSyntax expression, ITypeSymbol? containerType, bool unwrapNullable, bool isForDereference)
864ITypeSymbol? containerType,
872if (symbol.IsStatic || symbol is ITypeSymbol)
901var container = GetContainerForUnnamedSymbols(semanticModel, originalExpression);
920private ITypeSymbol? GetContainerForUnnamedSymbols(SemanticModel semanticModel, ExpressionSyntax originalExpression)
922return originalExpression.ShouldNameExpressionBeTreatedAsExpressionInsteadOfType(_context.SemanticModel, out _, out var container)
927private 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 (31)
128var castedType = semanticModel.GetTypeInfo(castExpression.Type, cancellationToken).Type;
163var castedType = semanticModel.GetTypeInfo(castExpression.Type, cancellationToken).Type;
167var parentCastType = semanticModel.GetTypeInfo(parentCast.Type, cancellationToken).Type;
314var originalConvertedType = originalSemanticModel.GetTypeInfo(castNode.WalkUpParentheses(), cancellationToken).ConvertedType;
506var castedExpressionType = originalSemanticModel.GetTypeInfo(castedExpressionNode, cancellationToken).Type;
507var isType = originalSemanticModel.GetTypeInfo(isExpression.Right, cancellationToken).Type;
543var targetType = castNode.GetTargetType(originalSemanticModel, cancellationToken);
608ITypeSymbol originalConvertedType,
612var castedType = originalSemanticModel.GetTypeInfo(castNode, cancellationToken).Type;
687var castType = semanticModel.GetTypeInfo(castNode, cancellationToken).Type;
807var originalConvertedType = originalConversionOperation.Type;
808var rewrittenBitwiseNotConversionType = rewrittenBitwiseNotConversionOperation.Type;
821private static bool IsSignedIntegralOrIntPtrType(ITypeSymbol? type)
885var castType = originalSemanticModel.GetTypeInfo(castExpression, cancellationToken).Type;
915var otherSideType = originalSemanticModel.GetTypeInfo(otherSide, cancellationToken).Type;
916var thisSideRewrittenType = rewrittenSemanticModel.GetTypeInfo(rewrittenExpression, cancellationToken).Type;
928var rewrittenConditionalConvertedType = rewrittenSemanticModel.GetTypeInfo(rewrittenConditionalExpression, cancellationToken).ConvertedType;
939private static bool IsNullOrErrorType([NotNullWhen(false)] ITypeSymbol? type)
1062var castSideType = semanticModel.GetTypeInfo(castSide, cancellationToken).Type;
1063var castedExpressionType = semanticModel.GetTypeInfo(castExpression.Expression, cancellationToken).Type;
1067var otherSideType = semanticModel.GetTypeInfo(otherSide, cancellationToken).Type;
1085var castType = semanticModel.GetTypeInfo(castNode, cancellationToken).Type;
1086var castedExpressionType = semanticModel.GetTypeInfo(castedExpressionNode, cancellationToken).Type;
1143private static bool IsFloatingPointType(ITypeSymbol? type)
1313var rewrittenType = rewrittenSemanticModel.GetTypeInfo(rewrittenExpression, cancellationToken).Type;
1428private static bool IsIntrinsicOrEnum(ITypeSymbol rewrittenType)
1436ITypeSymbol rewrittenType,
1526private static (ITypeSymbol? rewrittenConvertedType, Conversion rewrittenConversion) GetRewrittenInfo(
1529Conversion originalConversion, ITypeSymbol originalConvertedType,
1540var convertedType = originalConversion.IsIdentity ? originalConvertedType : originalSemanticModel.Compilation.ObjectType;
1544var rewrittenConvertedType = rewrittenSemanticModel.GetTypeInfo(rewrittenExpression, cancellationToken).ConvertedType;
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\CSharp\Utilities\SpeculationAnalyzer.cs (16)
385var originalExpressionType = originalExpressionTypeInfo.Type;
386var newExpressionType = newExpressionTypeInfo.Type;
434var originalCaseType = this.OriginalSemanticModel.GetTypeInfo(previousOriginalNode, this.CancellationToken).Type;
435var newCaseType = this.SpeculativeSemanticModel.GetTypeInfo(previousReplacedNode, this.CancellationToken).Type;
560var originalExpressionType = this.OriginalSemanticModel.GetTypeInfo(originalAnonymousObjectMemberDeclarator.Expression, this.CancellationToken).Type;
561var newExpressionType = this.SpeculativeSemanticModel.GetTypeInfo(replacedAnonymousObjectMemberDeclarator.Expression, this.CancellationToken).Type;
701var originalConvertedType = this.OriginalSemanticModel.GetTypeInfo(originalIsOrAsExpression.Right).Type;
702var newConvertedType = this.SpeculativeSemanticModel.GetTypeInfo(newIsOrAsExpression.Right).Type;
840protected override bool ConversionsAreCompatible(ExpressionSyntax originalExpression, ITypeSymbol originalTargetType, ExpressionSyntax newExpression, ITypeSymbol newTargetType)
888out ITypeSymbol elementType,
930protected override bool IsReferenceConversion(Compilation compilation, ITypeSymbol sourceType, ITypeSymbol targetType)
933protected override Conversion ClassifyConversion(SemanticModel model, ExpressionSyntax expression, ITypeSymbol targetType)
936protected override Conversion ClassifyConversion(SemanticModel model, ITypeSymbol originalType, ITypeSymbol targetType)
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\CSharp\CodeGeneration\ExpressionGenerator.cs (9)
34return typedConstant.Value is ITypeSymbol typeSymbol
54ITypeSymbol? type,
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 (31)
34protected override bool IsUnusableType(ITypeSymbol otherSideType)
615private static IMethodSymbol Instantiate(IMethodSymbol method, IList<ITypeSymbol> invocationTypes)
639IDictionary<ITypeParameterSymbol, ITypeSymbol> bestMap = null;
640foreach (var type in invocationTypes)
661private static Dictionary<ITypeParameterSymbol, ITypeSymbol> DetermineTypeParameterMapping(ITypeSymbol inferredType, ITypeSymbol returnType)
663var result = new Dictionary<ITypeParameterSymbol, ITypeSymbol>();
668private static void DetermineTypeParameterMapping(ITypeSymbol inferredType, ITypeSymbol returnType, Dictionary<ITypeParameterSymbol, ITypeSymbol> result)
1133static ITypeSymbol MakeNullable(ITypeSymbol symbol, Compilation compilation)
1447var type = this.SemanticModel.GetTypeInfo(recursivePattern).ConvertedType;
1566var elementTypesBuilder = ArrayBuilder<ITypeSymbol>.GetInstance(subPatternCount);
1591private static ImmutableArray<NullableAnnotation> GetNullableAnnotations(ImmutableArray<ITypeSymbol> elementTypes)
1780private ITypeSymbol InferTypeForFirstParameterOfLambda(
1795private ITypeSymbol InferTypeForFirstParameterOfParenthesizedLambda(
1804private ITypeSymbol InferTypeForFirstParameterOfSimpleLambda(
1811private ITypeSymbol InferTypeForFirstParameterOfLambda(
1818private ITypeSymbol InferTypeForFirstParameterOfLambda(
1836var type = InferTypeForFirstParameterOfLambda(parameterName, child.AsNode());
2001private ITypeSymbol UnwrapTaskLike(ITypeSymbol type, bool isAsync)
2270var tupleType = GetTupleType(tupleExpression);
2279private ITypeSymbol GetTupleType(
2293out ImmutableArray<ITypeSymbol> elementTypes,
2299using var _1 = ArrayBuilder<ITypeSymbol>.GetInstance(out var elementTypesBuilder);
2337ArrayBuilder<ITypeSymbol> elementTypesBuilder,
2359ArrayBuilder<ITypeSymbol> elementTypesBuilder,
2362var tupleType = GetTupleType(tuple);
AddImport\SymbolReferenceFinder.cs (9)
206var typeSymbols = OfType<ITypeSymbol>(symbols);
233ITypeSymbol symbol,
392ImmutableArray<SymbolResult<IMethodSymbol>> methodSymbols, ITypeSymbol typeSymbol)
449var type = _owner.GetQueryClauseInfo(_semanticModel, _node, cancellationToken);
473var type = GetAwaitInfo(_semanticModel, _syntaxFacts, _node);
498var type = GetCollectionExpressionType(_semanticModel, _syntaxFacts, _node);
523var type = GetCollectionExpressionType(_semanticModel, _syntaxFacts, _node);
548var type = _owner.GetDeconstructInfo(_semanticModel, _node, cancellationToken);
564SearchScope 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)
53ITypeSymbol receiverTypeSymbol,
55ImmutableArray<ITypeSymbol> targetTypesSymbols,
108ITypeSymbol receiverTypeSymbol,
110ImmutableArray<ITypeSymbol> targetTypes,
146Compilation compilation, ImmutableArray<IMethodSymbol> extentsionMethodSymbols, ImmutableArray<ITypeSymbol> targetTypeSymbols, CancellationToken cancellationToken)
148Dictionary<ITypeSymbol, bool> typeConvertibilityCache = [];
215Compilation compilation, IMethodSymbol methodSymbol, ImmutableArray<ITypeSymbol> targetTypeSymbols,
216Dictionary<ITypeSymbol, bool> typeConvertibilityCache)
Completion\Providers\ImportCompletionProvider\ExtensionMethodImportCompletionHelper.SymbolComputer.cs (14)
32private readonly ITypeSymbol _receiverTypeSymbol;
40private readonly ConcurrentDictionary<ITypeSymbol, bool> _checkedReceiverTypes = [];
45ITypeSymbol receiverTypeSymbol,
239MultiDictionary<ITypeSymbol, IMethodSymbol> matchingMethodSymbols,
306MultiDictionary<ITypeSymbol, IMethodSymbol> matchingMethodSymbols,
342private MultiDictionary<ITypeSymbol, IMethodSymbol> GetPotentialMatchingSymbolsFromAssembly(
348var builder = new MultiDictionary<ITypeSymbol, IMethodSymbol>();
383if (MatchExtensionMethod(methodSymbol, receiverTypeName, internalsVisible, out var receiverType))
394static bool MatchExtensionMethod(IMethodSymbol method, string filterReceiverTypeName, bool internalsVisible, out ITypeSymbol? receiverType)
475private static ImmutableArray<string> GetReceiverTypeNames(ITypeSymbol receiverTypeSymbol)
481static void AddNamesForTypeWorker(ITypeSymbol receiverTypeSymbol, PooledHashSet<string> builder)
485foreach (var constraintType in typeParameter.ConstraintTypes)
519private static string GetReceiverTypeName(ITypeSymbol typeSymbol)
527var elementType = arrayType.ElementType;
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 (8)
1808protected void AddRudeTypeUpdateAroundActiveStatement(RudeEditDiagnosticsBuilder diagnostics, SyntaxNode newNode, ITypeSymbol oldType, ITypeSymbol newType)
1991var oldType = oldModel.GetTypeInfo(oldTypedNodes[t], cancellationToken).Type;
1992var newType = newModel.GetTypeInfo(newTypedNodes[t], cancellationToken).Type;
2422protected static bool TypesEquivalent(ITypeSymbol? oldType, ITypeSymbol? newType, bool exact)
2423=> (exact ? s_exactSymbolEqualityComparer : (IEqualityComparer<ITypeSymbol?>)s_runtimeSymbolEqualityComparer.SignatureTypeEquivalenceComparer).Equals(oldType, newType);
2425protected static bool TypesEquivalent<T>(ImmutableArray<T> oldTypes, ImmutableArray<T> newTypes, bool exact) where T : ITypeSymbol
src\Analyzers\Core\Analyzers\RemoveUnusedParametersAndValues\AbstractRemoveUnusedParametersAndValuesDiagnosticAnalyzer.SymbolStartAnalyzer.cs (1)
292ITypeSymbol containingType,
src\Analyzers\Core\CodeFixes\AddExplicitCast\AbstractAddExplicitCastCodeFixProvider.cs (11)
30protected abstract TExpressionSyntax Cast(TExpressionSyntax expression, ITypeSymbol type);
48protected ImmutableArray<(TExpressionSyntax node, ITypeSymbol type)> GetPotentialTargetTypes(
52using var _ = ArrayBuilder<(TExpressionSyntax node, ITypeSymbol type)>.GetInstance(out var candidates);
63ArrayBuilder<(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)
46protected abstract ITypeSymbol GetArgumentType(SyntaxNode argumentNode, SemanticModel semanticModel, CancellationToken cancellationToken);
401private async Task<(ITypeSymbol, RefKind)> GetArgumentTypeAndRefKindAsync(Document invocationDocument, TArgumentSyntax argument, CancellationToken cancellationToken)
405var argumentType = GetArgumentType(argument, semanticModel, cancellationToken);
536Compilation compilation, TypeInfo argumentTypeInfo, ITypeSymbol parameterType,
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\VisualBasic\CodeGeneration\ExpressionGenerator.vb (12)
31If TypeOf typedConstant.Value IsNot ITypeSymbol Then
35Return SyntaxFactory.GetTypeExpression(DirectCast(typedConstant.Value, ITypeSymbol).GenerateTypeSyntax())
42Friend Function GenerateExpression(generator As SyntaxGenerator, type As ITypeSymbol, value As Object, canUseFieldReference As Boolean) As ExpressionSyntax
58Friend Function GenerateNonEnumValueExpression(type As ITypeSymbol, value As Object, canUseFieldReference As Boolean) As ExpressionSyntax
109Private Function GenerateStringLiteralExpression(type As ITypeSymbol, value As String) As ExpressionSyntax
162type As ITypeSymbol,
178type As ITypeSymbol,
225Private Sub DetermineSuffix(type As ITypeSymbol,
275Private Function GenerateDoubleLiteralExpression(type As ITypeSymbol,
300type As ITypeSymbol,
325type As ITypeSymbol,
373Private Function GenerateDecimalLiteralExpression(type As ITypeSymbol, value As Decimal, canUseFieldReference As Boolean) As ExpressionSyntax
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\VisualBasic\Utilities\CastAnalyzer.vb (11)
33Private Function CastPassedToParamArrayDefinitelyCantBeRemoved(castType As ITypeSymbol) As Boolean
57Private Shared Function GetOuterCastType(expression As ExpressionSyntax, expressionTypeInfo As TypeInfo, semanticModel As SemanticModel, cancellationToken As CancellationToken) As ITypeSymbol
122Private Shared Function GetSpeculatedExpressionToOuterTypeConversion(speculationAnalyzer As SpeculationAnalyzer, speculatedExpression As ExpressionSyntax, outerSpeculatedExpression As ExpressionSyntax, cancellationToken As CancellationToken, <Out> ByRef speculatedExpressionOuterType As ITypeSymbol) As Conversion
142Private Shared Function AsTypeInVariableDeclarator(node As SyntaxNode, semanticModel As SemanticModel) As ITypeSymbol
206Dim castExpressionType As ITypeSymbol
253Dim speculatedExpressionOuterType As ITypeSymbol = Nothing
319DirectCast(castExpressionType.OriginalDefinition, ITypeSymbol).SpecialType = SpecialType.System_Nullable_T
374Private Shared Function IsRequiredWideningNumericConversion(sourceType As ITypeSymbol, destinationType As ITypeSymbol) As Boolean
394Private Shared Function CastRemovalChangesDefaultValue(castType As ITypeSymbol, outerType As ITypeSymbol) As Boolean
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\VisualBasic\Utilities\SpeculationAnalyzer.vb (8)
547Protected Overrides Function ConversionsAreCompatible(originalExpression As ExpressionSyntax, originalTargetType As ITypeSymbol, newExpression As ExpressionSyntax, newTargetType As ITypeSymbol) As Boolean
600ByRef elementType As ITypeSymbol,
608Protected Overrides Function IsReferenceConversion(compilation As Compilation, sourceType As ITypeSymbol, targetType As ITypeSymbol) As Boolean
612Protected Overrides Function ClassifyConversion(model As SemanticModel, expression As ExpressionSyntax, targetType As ITypeSymbol) As Conversion
616Protected Overrides Function ClassifyConversion(model As SemanticModel, originalType As ITypeSymbol, targetType As ITypeSymbol) As Conversion
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\VisualBasic\CodeGeneration\ExpressionGenerator.vb (12)
31If TypeOf typedConstant.Value IsNot ITypeSymbol Then
35Return SyntaxFactory.GetTypeExpression(DirectCast(typedConstant.Value, ITypeSymbol).GenerateTypeSyntax())
42Friend Function GenerateExpression(generator As SyntaxGenerator, type As ITypeSymbol, value As Object, canUseFieldReference As Boolean) As ExpressionSyntax
58Friend Function GenerateNonEnumValueExpression(type As ITypeSymbol, value As Object, canUseFieldReference As Boolean) As ExpressionSyntax
109Private Function GenerateStringLiteralExpression(type As ITypeSymbol, value As String) As ExpressionSyntax
162type As ITypeSymbol,
178type As ITypeSymbol,
225Private Sub DetermineSuffix(type As ITypeSymbol,
275Private Function GenerateDoubleLiteralExpression(type As ITypeSymbol,
300type As ITypeSymbol,
325type As ITypeSymbol,
373Private Function GenerateDecimalLiteralExpression(type As ITypeSymbol, value As Decimal, canUseFieldReference As Boolean) As ExpressionSyntax
Editing\SyntaxGenerator.cs (20)
337private protected abstract SyntaxNode GenerateExpression(ITypeSymbol? type, object? value, bool canUseFieldReference);
1606/// <see langword="true"/> if the language requires a <see cref="TypeExpression(ITypeSymbol)"/>
1608/// <see cref="LocalDeclarationStatement(ITypeSymbol, string, SyntaxNode, bool)"/>.
1631public SyntaxNode LocalDeclarationStatement(ITypeSymbol type, string name, SyntaxNode? initializer = null, bool isConst = false)
1744public SyntaxNode CatchClause(ITypeSymbol type, string identifier, IEnumerable<SyntaxNode> statements)
1785public SyntaxNode DefaultExpression(ITypeSymbol type)
1854public SyntaxNode GenericName(string identifier, IEnumerable<ITypeSymbol> typeArguments)
1866public SyntaxNode GenericName(string identifier, params ITypeSymbol[] typeArguments)
1867=> GenericName(identifier, (IEnumerable<ITypeSymbol>)typeArguments);
1935public SyntaxNode TypeExpression(ITypeSymbol typeSymbol)
1943public SyntaxNode TypeExpression(ITypeSymbol typeSymbol, bool addImport)
1995public SyntaxNode TupleTypeExpression(IEnumerable<ITypeSymbol> elementTypes, IEnumerable<string>? elementNames = null)
2024public SyntaxNode TupleElementExpression(ITypeSymbol type, string? name = null)
2207public SyntaxNode ObjectCreationExpression(ITypeSymbol type, IEnumerable<SyntaxNode> arguments)
2219public SyntaxNode ObjectCreationExpression(ITypeSymbol type, params SyntaxNode[] arguments)
2274public SyntaxNode IsTypeExpression(SyntaxNode expression, ITypeSymbol type)
2285public SyntaxNode TryCastExpression(SyntaxNode expression, ITypeSymbol type)
2297public SyntaxNode CastExpression(ITypeSymbol type, SyntaxNode expression)
2309public SyntaxNode ConvertExpression(ITypeSymbol type, SyntaxNode expression)
2388public 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\Extensions\ITypeSymbolExtensions.cs (100)
23public static bool IsIntegralType([NotNullWhen(returnValue: true)] this ITypeSymbol? type)
26public static bool IsSignedIntegralType([NotNullWhen(returnValue: true)] this ITypeSymbol? type)
29public static bool CanAddNullCheck([NotNullWhen(returnValue: true)] this ITypeSymbol? type)
40public static IList<INamedTypeSymbol> GetAllInterfacesIncludingThis(this ITypeSymbol type)
56public static bool IsAbstractClass([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
59public static bool IsSystemVoid([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
62public static bool IsNullable([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
65public static bool IsNonNullableValueType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
69[NotNullWhen(true)] this ITypeSymbol? symbol,
70[NotNullWhen(true)] out ITypeSymbol? underlyingType)
82public static bool IsModuleType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
85public static bool IsInterfaceType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
88public static bool IsDelegateType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
91public static bool IsFunctionPointerType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
94public static bool IsStructType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
101this ITypeSymbol type,
115public static IEnumerable<ITypeSymbol> GetBaseTypesAndThis(this ITypeSymbol? type)
117var current = type;
125public static IEnumerable<INamedTypeSymbol> GetBaseTypes(this ITypeSymbol? type)
135public static IEnumerable<ITypeSymbol> GetContainingTypesAndThis(this ITypeSymbol? type)
137var current = type;
145public static IEnumerable<INamedTypeSymbol> GetContainingTypes(this ITypeSymbol type)
158this ITypeSymbol type, ITypeSymbol baseType, bool includeInterfaces)
171this ITypeSymbol type, ITypeSymbol baseType)
179this ITypeSymbol type, ITypeSymbol baseType)
181var originalBaseType = baseType.OriginalDefinition;
189IEnumerable<ITypeSymbol> baseTypes = (baseType.TypeKind == TypeKind.Interface) ? type.AllInterfaces : type.GetBaseTypes();
196this ITypeSymbol type, ITypeSymbol baseType)
198var originalBaseType = baseType.OriginalDefinition;
218this ITypeSymbol type, ITypeSymbol interfaceType)
220var originalInterfaceType = interfaceType.OriginalDefinition;
225this ITypeSymbol type, ITypeSymbol interfaceType)
230public static bool IsAttribute(this ITypeSymbol symbol)
248public static bool IsFormattableStringOrIFormattable([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
257this ITypeSymbol typeSymbol, bool allowDelegateAndEnumConstraints = false)
285public static bool IsNumericType([NotNullWhen(returnValue: true)] this ITypeSymbol? type)
311public static Accessibility DetermineMinimalAccessibility(this ITypeSymbol typeSymbol)
314public static bool ContainsAnonymousType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
330foreach (var typeArg in type.GetAllTypeArguments())
339public static string CreateParameterName(this ITypeSymbol type, bool capitalize = false)
360private static string GetParameterName(ITypeSymbol? type)
373public static bool IsSpecialType([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
404public static bool CanSupportCollectionInitializer(this ITypeSymbol typeSymbol, ISymbol within)
415public static INamedTypeSymbol? GetDelegateType(this ITypeSymbol? typeSymbol, Compilation compilation)
422var typeArgument = ((INamedTypeSymbol)typeSymbol).TypeArguments[0];
435public static IEnumerable<T> GetAccessibleMembersInBaseTypes<T>(this ITypeSymbol containingType, ISymbol within) where T : class, ISymbol
444public static ImmutableArray<T> GetAccessibleMembersInThisAndBaseTypes<T>(this ITypeSymbol? containingType, ISymbol within) where T : class, ISymbol
454public static ImmutableArray<T> GetAccessibleMembersInThisAndBaseTypes<T>(this ITypeSymbol? containingType, string memberName, ISymbol within) where T : class, ISymbol
464public static bool? AreMoreSpecificThan(this IList<ITypeSymbol> t1, IList<ITypeSymbol> t2)
499public static IEnumerable<T> SelectAccessibleMembers<T>(this IEnumerable<ITypeSymbol>? types, ISymbol within) where T : class, ISymbol
509private static IEnumerable<T> SelectAccessibleMembers<T>(this IEnumerable<ITypeSymbol>? types, string memberName, ISymbol within) where T : class, ISymbol
519private static bool? IsMoreSpecificThan(this ITypeSymbol t1, ITypeSymbol t2)
598public static bool IsOrDerivesFromExceptionType([NotNullWhen(returnValue: true)] this ITypeSymbol? type, Compilation compilation)
605foreach (var baseType in type.GetBaseTypesAndThis())
616foreach (var constraint in ((ITypeParameterSymbol)type).ConstraintTypes)
631public static bool IsEnumType([NotNullWhen(true)] this ITypeSymbol? type)
634public static bool IsEnumType([NotNullWhen(true)] this ITypeSymbol? type, [NotNullWhen(true)] out INamedTypeSymbol? enumType)
646public static bool? IsMutableValueType(this ITypeSymbol type)
648if (type.IsNullable(out var underlyingType))
725public static bool IsDisposable([NotNullWhen(returnValue: true)] this ITypeSymbol? type, [NotNullWhen(returnValue: true)] ITypeSymbol? iDisposableType)
730public static ITypeSymbol WithNullableAnnotationFrom(this ITypeSymbol type, ITypeSymbol symbolForNullableAnnotation)
734public static ITypeSymbol? RemoveNullableIfPresent(this ITypeSymbol? symbol)
736if (symbol.IsNullable(out var underlyingType))
744public static bool IsSpanOrReadOnlySpan([NotNullWhen(true)] this ITypeSymbol? type)
747public static bool IsSpan([NotNullWhen(true)] this ITypeSymbol? type)
763public static bool IsInlineArray([NotNullWhen(true)] this ITypeSymbol? type)
768public static ITypeSymbol? RemoveUnavailableTypeParameters(
769this ITypeSymbol? type,
777private static ITypeSymbol? RemoveUnavailableTypeParameters(
778this ITypeSymbol? type,
786public static ITypeSymbol? RemoveAnonymousTypes(
787this ITypeSymbol? type,
794public static ITypeSymbol? RemoveUnnamedErrorTypes(
795this ITypeSymbol? type,
802this ITypeSymbol? type, ArrayBuilder<ITypeParameterSymbol> result)
808this ITypeSymbol? type, ArrayBuilder<ITypeParameterSymbol> result)
814this ITypeSymbol? type, ArrayBuilder<ITypeParameterSymbol> result, bool onlyMethodTypeParameters)
823public static IList<ITypeParameterSymbol> GetReferencedTypeParameters(this ITypeSymbol? type)
831public static ITypeSymbol? SubstituteTypes<TType1, TType2>(
832this ITypeSymbol? type,
835where TType1 : ITypeSymbol
836where TType2 : ITypeSymbol
842public static ITypeSymbol? SubstituteTypes<TType1, TType2>(
843this ITypeSymbol? type,
846where TType1 : ITypeSymbol
847where TType2 : ITypeSymbol
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\Utilities\AbstractSpeculationAnalyzer.cs (25)
104protected abstract TConversion ClassifyConversion(SemanticModel model, TExpressionSyntax expression, ITypeSymbol targetType);
105protected abstract TConversion ClassifyConversion(SemanticModel model, ITypeSymbol originalType, ITypeSymbol targetType);
107protected abstract bool ConversionsAreCompatible(TExpressionSyntax originalExpression, ITypeSymbol originalTargetType, TExpressionSyntax newExpression, ITypeSymbol newTargetType);
108protected abstract bool IsReferenceConversion(Compilation model, ITypeSymbol sourceType, ITypeSymbol targetType);
114SemanticModel model, TForEachStatementSyntax forEach, out IMethodSymbol getEnumeratorMethod, out ITypeSymbol elementType, out ImmutableArray<ILocalSymbol> localVariables);
304private bool ImplicitConversionsAreCompatible(TExpressionSyntax originalExpression, ITypeSymbol originalTargetType, TExpressionSyntax newExpression, ITypeSymbol newTargetType)
739var previousOriginalType = this.OriginalSemanticModel.GetTypeInfo(previousOriginalNode).Type;
740var previousReplacedType = this.SpeculativeSemanticModel.GetTypeInfo(previousReplacedNode).Type;
779GetForEachSymbols(this.OriginalSemanticModel, forEachStatement, out var originalGetEnumerator, out var originalElementType, out var originalLocalVariables);
780GetForEachSymbols(this.SpeculativeSemanticModel, newForEachStatement, out var newGetEnumerator, out var newElementType, out var newLocalVariables);
825var expressionType = this.SpeculativeSemanticModel.GetTypeInfo(newForEachStatementExpression, CancellationToken).ConvertedType;
848var originalThrowExpressionType = this.OriginalSemanticModel.GetTypeInfo(originalThrowExpression).Type;
850var newThrowExpressionType = this.SpeculativeSemanticModel.GetTypeInfo(newThrowExpression).Type;
960var originalTargetType = this.OriginalSemanticModel.GetTypeInfo(originalLeft).Type;
963var newTargetType = this.SpeculativeSemanticModel.GetTypeInfo(newLeft).Type;
996var newReceiverType = newReceiver != null
1035var receiverType = semanticModel.GetTypeInfo(receiver).Type;
1195ITypeSymbol originalTargetType,
1197ITypeSymbol newTargetType,
1212var originalConvertedTypeSymbol = this.OriginalSemanticModel.GetTypeInfo(originalExpression).ConvertedType;
1218var newConvertedTypeSymbol = this.SpeculativeSemanticModel.GetTypeInfo(newExpression).ConvertedType;
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\Core\CodeGeneration\CodeGenerationSymbolFactory.cs (18)
35DeclarationModifiers modifiers, ITypeSymbol type,
52ITypeSymbol type,
84ITypeSymbol type, RefKind refKind, ImmutableArray<IPropertySymbol> explicitInterfaceImplementations, string name,
111ITypeSymbol type, string name,
157ITypeSymbol? returnType,
179ITypeSymbol? returnType,
200ITypeSymbol returnType,
225ITypeSymbol toType,
253ITypeSymbol toType,
269public static IParameterSymbol CreateParameterSymbol(ITypeSymbol type, string name)
272public static IParameterSymbol CreateParameterSymbol(RefKind refKind, ITypeSymbol type, string name)
282ImmutableArray<AttributeData> attributes, RefKind refKind, bool isParams, ITypeSymbol type, string name, bool isOptional = false, bool hasDefaultValue = false, object? defaultValue = null)
295ITypeSymbol? type = null,
336ImmutableArray<ITypeSymbol> constraintTypes,
352public static IPointerTypeSymbol CreatePointerTypeSymbol(ITypeSymbol pointedAtType)
358public static IArrayTypeSymbol CreateArrayTypeSymbol(ITypeSymbol elementType, int rank = 1, NullableAnnotation nullableAnnotation = NullableAnnotation.None)
468ITypeSymbol returnType,
525ITypeSymbol? 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)
20ITypeSymbol toType,
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\Core\CodeGeneration\Symbols\CodeGenerationOperatorSymbol.cs (1)
20ITypeSymbol returnType,