private static ITypeSymbol GetPropertyType( SimpleNameSyntax propertyName, SemanticModel semanticModel, ITypeInferenceService typeInference, CancellationToken cancellationToken ) { if (propertyName.Parent is AssignmentExpressionSyntax parentAssignment) { return(typeInference.InferType( semanticModel, parentAssignment.Left, objectAsDefault: true, cancellationToken: cancellationToken )); } if (propertyName.Parent is IsPatternExpressionSyntax isPatternExpression) { return(typeInference.InferType( semanticModel, isPatternExpression.Expression, objectAsDefault: true, cancellationToken: cancellationToken )); } return(null); }
protected override ITypeSymbol DetermineReturnTypeForSimpleNameOrMemberAccessExpression( ITypeInferenceService typeInferenceService, SemanticModel semanticModel, ExpressionSyntax expression, CancellationToken cancellationToken ) { if ( semanticModel.SyntaxTree.IsNameOfContext( expression.SpanStart, semanticModel, cancellationToken ) ) { return(typeInferenceService.InferType( semanticModel, expression, true, cancellationToken )); } return(null); }
private bool IsImplicitArrayCreation(SemanticModel semanticModel, SyntaxToken token, int position, ITypeInferenceService typeInferrer, CancellationToken cancellationToken) { if (token.IsKind(SyntaxKind.NewKeyword) && token.Parent.IsKind(SyntaxKind.ObjectCreationExpression)) { var type = typeInferrer.InferType(semanticModel, token.Parent, objectAsDefault: false, cancellationToken: cancellationToken); return(type != null && type is IArrayTypeSymbol); } return(false); }
private bool IsImplicitArrayCreation(SemanticModel semanticModel, SyntaxToken token, int position, ITypeInferenceService typeInferrer, CancellationToken cancellationToken) { if (token.IsKind(SyntaxKind.NewKeyword) && token.Parent.IsKind(SyntaxKind.ObjectCreationExpression)) { var type = typeInferrer.InferType(semanticModel, token.Parent, objectAsDefault: false, cancellationToken: cancellationToken); return type != null && type is IArrayTypeSymbol; } return false; }
public static INamedTypeSymbol InferDelegateType( this ITypeInferenceService typeInferenceService, SemanticModel semanticModel, SyntaxNode expression, CancellationToken cancellationToken) { var type = typeInferenceService.InferType(semanticModel, expression, objectAsDefault: false, cancellationToken: cancellationToken); return(type.GetDelegateType(semanticModel.Compilation)); }
private ITypeSymbol GetPropertyType( SimpleNameSyntax property, SemanticModel semanticModel, ITypeInferenceService typeInference, CancellationToken cancellationToken) { var parent = property.Parent as AssignmentExpressionSyntax; if (parent != null) { return(typeInference.InferType(semanticModel, parent.Left, true, cancellationToken)); } return(null); }
private static bool IsPossibleOutVariableDeclaration(SyntaxToken token, SemanticModel semanticModel, int position, ITypeInferenceService typeInferenceService, CancellationToken cancellationToken, out NameDeclarationInfo result) { if (!token.IsKind(SyntaxKind.IdentifierToken) || !(token.Parent.IsKind(SyntaxKind.IdentifierName))) { result = default; return(false); } var argument = token.Parent.Parent as ArgumentSyntax // var is child of ArgumentSyntax, eg. Goo(out var $$ ?? token.Parent.Parent.Parent as ArgumentSyntax; // var is child of DeclarationExpression // under ArgumentSyntax, eg. Goo(out var a$$ if (argument == null || !argument.RefOrOutKeyword.IsKind(SyntaxKind.OutKeyword)) { result = default; return(false); } var type = typeInferenceService.InferType(semanticModel, argument.SpanStart, objectAsDefault: false, cancellationToken: cancellationToken); if (type != null) { result = new NameDeclarationInfo( ImmutableArray.Create(SymbolKind.Local), Accessibility.NotApplicable, new DeclarationModifiers(), type, alias: null); return(true); } result = default; return(false); }