private bool TryInitializeVariableDeclarationCase() { if (!_syntaxFacts.IsLocalDeclarationStatement(_containingStatement)) { return(false); } if (!(_objectCreationExpression.Parent.Parent is TVariableDeclaratorSyntax containingDeclarator)) { return(false); } _initializedSymbol = _semanticModel.GetDeclaredSymbol(containingDeclarator, _cancellationToken); if (_initializedSymbol is ILocalSymbol local && local.Type is IDynamicTypeSymbol) { // Not supported if we're creating a dynamic local. The object we're instantiating // may not have the members that we're trying to access on the dynamic object. return(false); } if (!_syntaxFacts.IsDeclaratorOfLocalDeclarationStatement(containingDeclarator, _containingStatement)) { return(false); } _valuePattern = _syntaxFacts.GetIdentifierOfVariableDeclarator(containingDeclarator); return(true); }
private bool TryInitializeVariableDeclarationCase() { if (!_syntaxFacts.IsLocalDeclarationStatement(_containingStatement)) { return(false); } var containingDeclarator = _objectCreationExpression.FirstAncestorOrSelf <TVariableDeclaratorSyntax>(); if (containingDeclarator == null) { return(false); } if (!_syntaxFacts.IsDeclaratorOfLocalDeclarationStatement(containingDeclarator, _containingStatement)) { return(false); } _valuePattern = _syntaxFacts.GetIdentifierOfVariableDeclarator(containingDeclarator); return(true); }