当前位置: 首页>>代码示例>>C#>>正文


C# ExpressionSyntax.Kind方法代码示例

本文整理汇总了C#中ExpressionSyntax.Kind方法的典型用法代码示例。如果您正苦于以下问题:C# ExpressionSyntax.Kind方法的具体用法?C# ExpressionSyntax.Kind怎么用?C# ExpressionSyntax.Kind使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ExpressionSyntax的用法示例。


在下文中一共展示了ExpressionSyntax.Kind方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: InvertConditionInternal

        static ExpressionSyntax InvertConditionInternal(ExpressionSyntax condition)
        {
            if (condition is ParenthesizedExpressionSyntax)
            {
                return SyntaxFactory.ParenthesizedExpression(InvertCondition(((ParenthesizedExpressionSyntax)condition).Expression));
            }

            if (condition is PrefixUnaryExpressionSyntax)
            {
                var uOp = (PrefixUnaryExpressionSyntax)condition;
                if (uOp.IsKind(SyntaxKind.LogicalNotExpression))
                {
                    if (!(uOp.Parent is ExpressionSyntax))
                        return uOp.Operand.SkipParens();
                    return uOp.Operand;
                }
                return SyntaxFactory.PrefixUnaryExpression(SyntaxKind.LogicalNotExpression, uOp);
            }

            if (condition is BinaryExpressionSyntax)
            {
                var bOp = (BinaryExpressionSyntax)condition;

                if (bOp.IsKind(SyntaxKind.LogicalAndExpression) || bOp.IsKind(SyntaxKind.LogicalOrExpression))
                    return SyntaxFactory.BinaryExpression(NegateConditionOperator(bOp.Kind()), InvertCondition(bOp.Left), InvertCondition(bOp.Right));

                if (bOp.IsKind(SyntaxKind.EqualsExpression) ||
                    bOp.IsKind(SyntaxKind.NotEqualsExpression) ||
                    bOp.IsKind(SyntaxKind.GreaterThanExpression) ||
                    bOp.IsKind(SyntaxKind.GreaterThanOrEqualExpression) ||
                    bOp.IsKind(SyntaxKind.LessThanExpression) ||
                    bOp.IsKind(SyntaxKind.LessThanOrEqualExpression))
                    return SyntaxFactory.BinaryExpression(NegateRelationalOperator(bOp.Kind()), bOp.Left, bOp.Right);

                return SyntaxFactory.PrefixUnaryExpression(SyntaxKind.LogicalNotExpression, SyntaxFactory.ParenthesizedExpression(condition));
            }

            if (condition is ConditionalExpressionSyntax)
            {
                var cEx = condition as ConditionalExpressionSyntax;
                return cEx.WithCondition(InvertCondition(cEx.Condition));
            }

            if (condition is LiteralExpressionSyntax)
            {
                if (condition.Kind() == SyntaxKind.TrueLiteralExpression)
                    return SyntaxFactory.LiteralExpression(SyntaxKind.FalseLiteralExpression);
                if (condition.Kind() == SyntaxKind.FalseLiteralExpression)
                    return SyntaxFactory.LiteralExpression(SyntaxKind.TrueLiteralExpression);
            }

            return SyntaxFactory.PrefixUnaryExpression(SyntaxKind.LogicalNotExpression, AddParensIfRequired(condition, false));
        }
开发者ID:ceddlyburge,项目名称:RefactoringEssentials,代码行数:53,代码来源:CSharpUtil.cs

示例2: CollectLocalsFromDeconstruction

        internal void CollectLocalsFromDeconstruction(
            ExpressionSyntax declaration,
            LocalDeclarationKind kind,
            ArrayBuilder<LocalSymbol> locals,
            SyntaxNode deconstructionStatement,
            Binder enclosingBinderOpt = null)
        {
            switch (declaration.Kind())
            {
                case SyntaxKind.TupleExpression:
                    {
                        var tuple = (TupleExpressionSyntax)declaration;
                        foreach (var arg in tuple.Arguments)
                        {
                            CollectLocalsFromDeconstruction(arg.Expression, kind, locals, deconstructionStatement, enclosingBinderOpt);
                        }
                        break;
                    }
                case SyntaxKind.DeclarationExpression:
                    {
                        var declarationExpression = (DeclarationExpressionSyntax)declaration;
                        CollectLocalsFromDeconstruction(
                            declarationExpression.Designation, declarationExpression.Type,
                            kind, locals, deconstructionStatement, enclosingBinderOpt);

                        break;
                    }
                case SyntaxKind.IdentifierName:
                    break;
                default:
                    // In broken code, we can have an arbitrary expression here. Collect its expression variables.
                    ExpressionVariableFinder.FindExpressionVariables(this, locals, declaration);
                    break;
            }
        }
开发者ID:XieShuquan,项目名称:roslyn,代码行数:35,代码来源:ForEachLoopBinder.cs

示例3: CollectLocalsFromDeconstruction

        internal void CollectLocalsFromDeconstruction(
            ExpressionSyntax declaration,
            LocalDeclarationKind kind,
            ArrayBuilder<LocalSymbol> locals,
            SyntaxNode deconstructionStatement,
            Binder enclosingBinderOpt = null)
        {
            switch (declaration.Kind())
            {
                case SyntaxKind.TupleExpression:
                    {
                        var tuple = (TupleExpressionSyntax)declaration;
                        foreach (var arg in tuple.Arguments)
                        {
                            CollectLocalsFromDeconstruction(arg.Expression, kind, locals, deconstructionStatement, enclosingBinderOpt);
                        }
                        break;
                    }
                case SyntaxKind.DeclarationExpression:
                    {
                        var declarationExpression = (DeclarationExpressionSyntax)declaration;
                        CollectLocalsFromDeconstruction(
                            declarationExpression.Designation, declarationExpression.Type,
                            kind, locals, deconstructionStatement, enclosingBinderOpt);

                        break;
                    }
                case SyntaxKind.IdentifierName:
                    break;
                default:
                    throw ExceptionUtilities.UnexpectedValue(declaration.Kind());
            }
        }
开发者ID:GuilhermeSa,项目名称:roslyn,代码行数:33,代码来源:ForEachLoopBinder.cs

示例4: IsConstant

            private bool IsConstant(ExpressionSyntax expression)
            {
                switch (expression.Kind())
                {
                    case SyntaxKind.CharacterLiteralExpression:
                    case SyntaxKind.FalseLiteralExpression:
                    case SyntaxKind.NullLiteralExpression:
                    case SyntaxKind.NumericLiteralExpression:
                    case SyntaxKind.StringLiteralExpression:
                    case SyntaxKind.TrueLiteralExpression:
                        {
                            return true;
                        }

                    case SyntaxKind.SimpleMemberAccessExpression:
                    case SyntaxKind.IdentifierName:
                        {
                            ISymbol symbol = _model.GetSymbolInfo(expression).Symbol;

                            if (symbol != null && symbol.Kind == SymbolKind.Field)
                            {
                                return ((IFieldSymbol)symbol).IsConst;
                            }

                            break;
                        }
                }

                return false;
            }
开发者ID:transformersprimeabcxyz,项目名称:_TO-DO-codeformatter-dotnet,代码行数:30,代码来源:AssertArgumentOrderConverter.cs

示例5: GetResolvedString

        internal static string GetResolvedString(SyntaxNodeAnalysisContext context, ExpressionSyntax expression, ref bool isNotConstant)
        {
            if (expression == null)
                return string.Empty;

            string result;
            if (_conditionalWeakTable.TryGetValue(expression, out result))
            {
                return result;
            }

            switch (expression.Kind())
            {
                case SyntaxKind.AddExpression:
                    var addExpression = (BinaryExpressionSyntax)expression;
                    result = GetResolvedString(context, addExpression.Left, ref isNotConstant) + GetResolvedString(context, addExpression.Right, ref isNotConstant);
                    break;
                case SyntaxKind.IdentifierName:
                    var value = context.SemanticModel.GetConstantValue(expression);
                    result = value.HasValue ? value.Value as string : string.Empty;
                    break;
                case SyntaxKind.StringLiteralExpression:
                    var literalExpression = (LiteralExpressionSyntax)expression;
                    result = literalExpression.Token.Value as string;
                    break;
                default:
                    isNotConstant = true;
                    result = string.Empty;
                    break;
            }

            _conditionalWeakTable.Add(expression, result);
            return result;
        }
开发者ID:RichiCoder1,项目名称:DapperDiagnostics,代码行数:34,代码来源:SemanticStringHelpers.cs

示例6: AssertDeconstructionIsAssignment

 private void AssertDeconstructionIsAssignment(ExpressionSyntax expression)
 {
     switch (expression.Kind())
     {
         case SyntaxKind.DeclarationExpression:
             Debug.Assert(false);
             break;
         case SyntaxKind.TupleExpression:
             var tuple = (TupleExpressionSyntax)expression;
             foreach (var arg in tuple.Arguments)
             {
                 AssertDeconstructionIsAssignment(arg.Expression);
             }
             break;
         default:
             return;
     }
 }
开发者ID:otawfik-ms,项目名称:roslyn,代码行数:18,代码来源:Binder_Deconstruct.cs

示例7: RegionAnalysisContext

        private RegionAnalysisContext RegionAnalysisContext(ExpressionSyntax expression)
        {
            while (expression.Kind() == SyntaxKind.ParenthesizedExpression)
                expression = ((ParenthesizedExpressionSyntax)expression).Expression;

            var memberModel = GetMemberModel(expression);
            if (memberModel == null)
            {
                // Recover from error cases
                var node = new BoundBadStatement(expression, ImmutableArray<BoundNode>.Empty, hasErrors: true);
                return new RegionAnalysisContext(Compilation, null, node, node, node);
            }

            Symbol member;
            BoundNode boundNode = GetBoundRoot(memberModel, out member);
            var first = memberModel.GetUpperBoundNode(expression, promoteToBindable: true);
            var last = first;
            return new RegionAnalysisContext(this.Compilation, member, boundNode, first, last);
        }
开发者ID:Rickinio,项目名称:roslyn,代码行数:19,代码来源:SyntaxTreeSemanticModel_RegionAnalysisContext.cs

示例8: DecomposeName

		/// <summary>
		/// Decomposes a name or member access expression into its component parts.
		/// </summary>
		/// <param name="expression">The name or member access expression.</param>
		/// <param name="qualifier">The qualifier (or left-hand-side) of the name expression. This may be null if there is no qualifier.</param>
		/// <param name="name">The name of the expression.</param>
		/// <param name="arity">The number of generic type parameters.</param>
		private static void DecomposeName(ExpressionSyntax expression, out ExpressionSyntax qualifier, out string name, out int arity)
		{
			switch (expression.Kind())
			{
			case SyntaxKind.SimpleMemberAccessExpression:
			case SyntaxKind.PointerMemberAccessExpression:
				var max = (MemberAccessExpressionSyntax)expression;
				qualifier = max.Expression;
				name = max.Name.Identifier.ValueText;
				arity = max.Name.Arity;
				break;
			case SyntaxKind.QualifiedName:
				var qn = (QualifiedNameSyntax)expression;
				qualifier = qn.Left;
				name = qn.Right.Identifier.ValueText;
				arity = qn.Arity;
				break;
			case SyntaxKind.AliasQualifiedName:
				var aq = (AliasQualifiedNameSyntax)expression;
				qualifier = aq.Alias;
				name = aq.Name.Identifier.ValueText;
				arity = aq.Name.Arity;
				break;
			case SyntaxKind.GenericName:
				var gx = (GenericNameSyntax)expression;
				qualifier = null;
				name = gx.Identifier.ValueText;
				arity = gx.Arity;
				break;
			case SyntaxKind.IdentifierName:
				var nx = (IdentifierNameSyntax)expression;
				qualifier = null;
				name = nx.Identifier.ValueText;
				arity = 0;
				break;
			default:
				qualifier = null;
				name = null;
				arity = 0;
				break;
			}
		}
开发者ID:pabloescribanoloza,项目名称:monodevelop,代码行数:49,代码来源:SemanticModelExtensions.cs

示例9: BindDeconstructionVariables

        /// <summary>
        /// Prepares locals (or fields in global statement) and lvalue expressions corresponding to the variables of the declaration.
        /// The locals/fields/lvalues are kept in a tree which captures the nesting of variables.
        /// Each local or field is either a simple local or field access (when its type is known) or a deconstruction variable pending inference.
        /// The caller is responsible for releasing the nested ArrayBuilders.
        /// </summary>
        private DeconstructionVariable BindDeconstructionVariables(
            ExpressionSyntax node,
            DiagnosticBag diagnostics,
            ref DeclarationExpressionSyntax declaration,
            ref ExpressionSyntax expression)
        {
            switch (node.Kind())
            {
                case SyntaxKind.DeclarationExpression:
                    {
                        var component = (DeclarationExpressionSyntax)node;
                        if (declaration == null)
                        {
                            declaration = component;
                        }

                        bool isVar;
                        bool isConst = false;
                        AliasSymbol alias;
                        TypeSymbol declType = BindVariableType(component.Designation, diagnostics, component.Type, ref isConst, out isVar, out alias);
                        Debug.Assert(isVar == ((object)declType == null));
                        if (component.Designation.Kind() == SyntaxKind.ParenthesizedVariableDesignation && !isVar)
                        {
                            // An explicit is not allowed with a parenthesized designation
                            Error(diagnostics, ErrorCode.ERR_DeconstructionVarFormDisallowsSpecificType, component.Designation);
                        }

                        return BindDeconstructionVariables(declType, component.Designation, diagnostics);
                    }
                case SyntaxKind.TupleExpression:
                    {
                        var component = (TupleExpressionSyntax)node;
                        var builder = ArrayBuilder<DeconstructionVariable>.GetInstance(component.Arguments.Count);
                        foreach (var arg in component.Arguments)
                        {
                            if (arg.NameColon != null)
                            {
                                Error(diagnostics, ErrorCode.ERR_TupleElementNamesInDeconstruction, arg.NameColon);
                            }

                            builder.Add(BindDeconstructionVariables(arg.Expression, diagnostics, ref declaration, ref expression));
                        }

                        return new DeconstructionVariable(builder, node);
                    }
                default:
                    var boundVariable = BindExpression(node, diagnostics, invoked: false, indexed: false);
                    var checkedVariable = CheckValue(boundVariable, BindValueKind.Assignment, diagnostics);
                    if (expression == null && checkedVariable.Kind != BoundKind.DiscardExpression)
                    {
                        expression = node;
                    }

                    return new DeconstructionVariable(checkedVariable, node);
            }
        }
开发者ID:XieShuquan,项目名称:roslyn,代码行数:62,代码来源:Binder_Deconstruct.cs

示例10: FullyQualifyIdentifierName

            private ExpressionSyntax FullyQualifyIdentifierName(
                ISymbol symbol,
                ExpressionSyntax rewrittenNode,
                ExpressionSyntax originalNode,
                bool replaceNode,
                bool isInsideCref,
                bool omitLeftHandSide)
            {
                Debug.Assert(!replaceNode || rewrittenNode.Kind() == SyntaxKind.IdentifierName);

                //// TODO: use and expand Generate*Syntax(isymbol) to not depend on symbol display any more.
                //// See GenerateExpressionSyntax();

                var result = rewrittenNode;

                // only if this symbol has a containing type or namespace there is work for us to do.
                if (replaceNode || symbol.ContainingType != null || symbol.ContainingNamespace != null)
                {
                    ImmutableArray<SymbolDisplayPart> displayParts;

                    ExpressionSyntax left = null;

                    // we either need to create an AliasQualifiedName if the symbol is directly contained in the global namespace,
                    // otherwise it a QualifiedName.
                    if (!replaceNode && symbol.ContainingType == null && symbol.ContainingNamespace.IsGlobalNamespace)
                    {
                        return rewrittenNode.CopyAnnotationsTo(
                            SyntaxFactory.AliasQualifiedName(
                                SyntaxFactory.IdentifierName(SyntaxFactory.Token(SyntaxKind.GlobalKeyword)),
                                (SimpleNameSyntax)rewrittenNode.WithLeadingTrivia(null))
                                    .WithLeadingTrivia(rewrittenNode.GetLeadingTrivia()));
                    }

                    displayParts = replaceNode
                        ? symbol.ToDisplayParts(s_typeNameFormatWithGenerics)
                        : (symbol.ContainingType ?? (ISymbol)symbol.ContainingNamespace).ToDisplayParts(s_typeNameFormatWithGenerics);

                    rewrittenNode = TryAddTypeArgumentToIdentifierName(rewrittenNode, symbol);

                    // Replaces the '<' token with the '{' token since we are inside crefs
                    rewrittenNode = TryReplaceAngleBracesWithCurlyBraces(rewrittenNode, isInsideCref);
                    result = rewrittenNode;

                    if (!omitLeftHandSide)
                    {
                        left = SyntaxFactory.ParseTypeName(displayParts.ToDisplayString());

                        // Replaces the '<' token with the '{' token since we are inside crefs
                        left = TryReplaceAngleBracesWithCurlyBraces(left, isInsideCref);

                        if (replaceNode)
                        {
                            return left
                                .WithLeadingTrivia(rewrittenNode.GetLeadingTrivia())
                                .WithTrailingTrivia(rewrittenNode.GetTrailingTrivia());
                        }

                        // now create syntax for the combination of left and right syntax, or a simple replacement in case of an identifier
                        var parent = originalNode.Parent;
                        var leadingTrivia = rewrittenNode.GetLeadingTrivia();
                        rewrittenNode = rewrittenNode.WithLeadingTrivia(null);

                        switch (parent.Kind())
                        {
                            case SyntaxKind.QualifiedName:
                                var qualifiedParent = (QualifiedNameSyntax)parent;

                                result = rewrittenNode.CopyAnnotationsTo(
                                    SyntaxFactory.QualifiedName(
                                        (NameSyntax)left,
                                        (SimpleNameSyntax)rewrittenNode));

                                break;

                            case SyntaxKind.SimpleMemberAccessExpression:
                                var memberAccessParent = (MemberAccessExpressionSyntax)parent;

                                result = rewrittenNode.CopyAnnotationsTo(
                                    SyntaxFactory.MemberAccessExpression(
                                        SyntaxKind.SimpleMemberAccessExpression,
                                        left,
                                        (SimpleNameSyntax)rewrittenNode));

                                break;

                            default:
                                Debug.Assert(rewrittenNode is SimpleNameSyntax);

                                if (SyntaxFacts.IsInNamespaceOrTypeContext(originalNode))
                                {
                                    var right = (SimpleNameSyntax)rewrittenNode;
                                    result = rewrittenNode.CopyAnnotationsTo(SyntaxFactory.QualifiedName((NameSyntax)left, right.WithAdditionalAnnotations(Simplifier.SpecialTypeAnnotation)));
                                }
                                else if (originalNode.Parent is CrefSyntax)
                                {
                                    var right = (SimpleNameSyntax)rewrittenNode;
                                    result = rewrittenNode.CopyAnnotationsTo(SyntaxFactory.QualifiedName((NameSyntax)left, right));
                                }
                                else
                                {
//.........这里部分代码省略.........
开发者ID:RoryVL,项目名称:roslyn,代码行数:101,代码来源:CSharpSimplificationService.Expander.cs

示例11: TryAddTypeArgumentToIdentifierName

            private ExpressionSyntax TryAddTypeArgumentToIdentifierName(ExpressionSyntax newNode, ISymbol symbol)
            {
                if (newNode.Kind() == SyntaxKind.IdentifierName && symbol.Kind == SymbolKind.Method)
                {
                    if (((IMethodSymbol)symbol).TypeArguments.Length != 0)
                    {
                        var typeArguments = ((IMethodSymbol)symbol).TypeArguments;
                        if (!typeArguments.Any(t => t.ContainsAnonymousType()))
                        {
                            var genericName = SyntaxFactory.GenericName(
                                            ((IdentifierNameSyntax)newNode).Identifier,
                                            SyntaxFactory.TypeArgumentList(
                                                SyntaxFactory.SeparatedList(
                                                    typeArguments.Select(p => SyntaxFactory.ParseTypeName(p.ToDisplayParts(s_typeNameFormatWithGenerics).ToDisplayString())))))
                                            .WithLeadingTrivia(newNode.GetLeadingTrivia())
                                            .WithTrailingTrivia(newNode.GetTrailingTrivia())
                                            .WithAdditionalAnnotations(Simplifier.Annotation);

                            genericName = newNode.CopyAnnotationsTo(genericName);
                            return genericName;
                        }
                    }
                }

                return newNode;
            }
开发者ID:RoryVL,项目名称:roslyn,代码行数:26,代码来源:CSharpSimplificationService.Expander.cs

示例12: TryGenerateLiteral

        private bool TryGenerateLiteral(ExpressionSyntax expression)
        {
            /*
                <ElementType name="Literal" content="eltOnly">
                - <group order="one">
                    <element type="Null" /> 
                    <element type="Number" /> 
                    <element type="Boolean" /> 
                    <element type="Char" /> 
                    <element type="String" /> 
                    <element type="Array" /> 
                    <element type="Type" /> 
                    </group>
                </ElementType>
            */

            using (LiteralTag())
            {
                var constantValue = SemanticModel.GetConstantValue(expression);
                if (!constantValue.HasValue)
                {
                    return false;
                }

                var type = SemanticModel.GetTypeInfo(expression).Type;
                if (type == null)
                {
                    return false;
                }

                switch (expression.Kind())
                {
                    case SyntaxKind.UnaryMinusExpression:
                    case SyntaxKind.NumericLiteralExpression:
                        GenerateNumber(constantValue.Value, type);
                        return true;

                    case SyntaxKind.CharacterLiteralExpression:
                        GenerateChar((char)constantValue.Value);
                        return true;

                    case SyntaxKind.StringLiteralExpression:
                        GenerateString((string)constantValue.Value);
                        return true;

                    case SyntaxKind.TrueLiteralExpression:
                    case SyntaxKind.FalseLiteralExpression:
                        GenerateBoolean((bool)constantValue.Value);
                        return true;
                }

                return false;
            }
        }
开发者ID:ehsansajjad465,项目名称:roslyn,代码行数:54,代码来源:MethodXmlBuilder.cs

示例13: TryNegateBinaryComparisonExpression

        private bool TryNegateBinaryComparisonExpression(
            ExpressionSyntax expression,
            SemanticModel semanticModel,
            CancellationToken cancellationToken,
            out ExpressionSyntax result)
        {
            Tuple<SyntaxKind, SyntaxKind> tuple;
            if (s_binaryMap.TryGetValue(expression.Kind(), out tuple))
            {
                var binaryExpression = (BinaryExpressionSyntax)expression;
                var expressionType = tuple.Item1;
                var operatorType = tuple.Item2;

                // Special case negating Length > 0 to Length == 0 and 0 < Length to 0 == Length
                // for arrays and strings. We can do this because we know that Length cannot be
                // less than 0. Additionally, if we find Length == 0 or 0 == Length, we'll invert
                // it to Length > 0 or 0 < Length, respectively.
                if (IsComparisonOfZeroAndSomethingNeverLessThanZero(binaryExpression, semanticModel, cancellationToken))
                {
                    operatorType = binaryExpression.OperatorToken.Kind() == SyntaxKind.EqualsEqualsToken
                        ? binaryExpression.Right is LiteralExpressionSyntax ? SyntaxKind.GreaterThanToken : SyntaxKind.LessThanToken
                        : SyntaxKind.EqualsEqualsToken;
                    expressionType = binaryExpression.Kind() == SyntaxKind.EqualsExpression
                        ? binaryExpression.Right is LiteralExpressionSyntax ? SyntaxKind.GreaterThanExpression : SyntaxKind.LessThanExpression
                        : SyntaxKind.EqualsExpression;
                }

                result = SyntaxFactory.BinaryExpression(
                    expressionType,
                    binaryExpression.Left,
                    SyntaxFactory.Token(
                        binaryExpression.OperatorToken.LeadingTrivia,
                        operatorType,
                        binaryExpression.OperatorToken.TrailingTrivia),
                    binaryExpression.Right);

                return true;
            }

            result = null;
            return false;
        }
开发者ID:RoryVL,项目名称:roslyn,代码行数:42,代码来源:InvertIfCodeRefactoringProvider.cs

示例14: WillConflictWithExistingLocal

        private static bool WillConflictWithExistingLocal(ExpressionSyntax expression, ExpressionSyntax simplifiedNode)
        {
            if (simplifiedNode.Kind() == SyntaxKind.IdentifierName && !SyntaxFacts.IsInNamespaceOrTypeContext(expression))
            {
                var identifierName = (IdentifierNameSyntax)simplifiedNode;
                var enclosingDeclarationSpace = FindImmediatelyEnclosingLocalVariableDeclarationSpace(expression);
                var enclosingMemberDeclaration = expression.FirstAncestorOrSelf<MemberDeclarationSyntax>();
                if (enclosingDeclarationSpace != null && enclosingMemberDeclaration != null)
                {
                    var locals = enclosingMemberDeclaration.GetLocalDeclarationMap()[identifierName.Identifier.ValueText];
                    foreach (var token in locals)
                    {
                        if (token.GetAncestors<SyntaxNode>().Contains(enclosingDeclarationSpace))
                        {
                            return true;
                        }
                    }
                }
            }

            return false;
        }
开发者ID:nileshjagtap,项目名称:roslyn,代码行数:22,代码来源:ExpressionSyntaxExtensions.cs

示例15: AddSubExpressionTerms

        private static void AddSubExpressionTerms(ExpressionSyntax expression, IList<string> terms, ref ExpressionType expressionType)
        {
            // Check here rather than at all the call sites...
            if (expression == null)
            {
                return;
            }

            switch (expression.Kind())
            {
                case SyntaxKind.ThisExpression:
                case SyntaxKind.BaseExpression:
                    // an op term is ok if it's a "this" or "base" op it allows us to see
                    // "this.foo" in the autos window note: it's not a VALIDTERM since we don't
                    // want "this" showing up in the auto's window twice.
                    expressionType = ExpressionType.ValidExpression;
                    return;

                case SyntaxKind.IdentifierName:
                    // Name nodes are always valid terms
                    expressionType = ExpressionType.ValidTerm;
                    return;

                case SyntaxKind.CharacterLiteralExpression:
                case SyntaxKind.FalseLiteralExpression:
                case SyntaxKind.NullLiteralExpression:
                case SyntaxKind.NumericLiteralExpression:
                case SyntaxKind.StringLiteralExpression:
                case SyntaxKind.TrueLiteralExpression:
                    // Constants can make up a valid term, but we don't consider them valid
                    // terms themselves (since we don't want them to show up in the autos window
                    // on their own).
                    expressionType = ExpressionType.ValidExpression;
                    return;

                case SyntaxKind.CastExpression:
                    AddCastExpressionTerms((CastExpressionSyntax)expression, terms, ref expressionType);
                    return;

                case SyntaxKind.SimpleMemberAccessExpression:
                case SyntaxKind.PointerMemberAccessExpression:
                    AddMemberAccessExpressionTerms((MemberAccessExpressionSyntax)expression, terms, ref expressionType);
                    return;

                case SyntaxKind.ObjectCreationExpression:
                    AddObjectCreationExpressionTerms((ObjectCreationExpressionSyntax)expression, terms, ref expressionType);
                    return;

                case SyntaxKind.ArrayCreationExpression:
                    AddArrayCreationExpressionTerms((ArrayCreationExpressionSyntax)expression, terms, ref expressionType);
                    return;

                case SyntaxKind.InvocationExpression:
                    AddInvocationExpressionTerms((InvocationExpressionSyntax)expression, terms, ref expressionType);
                    return;
            }

            // +, -, ++, --, !, etc.
            //
            // This is a valid expression if it doesn't have obvious side effects (i.e. ++, --)
            if (expression is PrefixUnaryExpressionSyntax)
            {
                AddPrefixUnaryExpressionTerms((PrefixUnaryExpressionSyntax)expression, terms, ref expressionType);
                return;
            }

            if (expression is AwaitExpressionSyntax)
            {
                AddAwaitExpressionTerms((AwaitExpressionSyntax)expression, terms, ref expressionType);
                return;
            }

            if (expression is PostfixUnaryExpressionSyntax)
            {
                AddPostfixUnaryExpressionTerms((PostfixUnaryExpressionSyntax)expression, terms, ref expressionType);
                return;
            }

            if (expression is BinaryExpressionSyntax)
            {
                var binaryExpression = (BinaryExpressionSyntax)expression;
                AddBinaryExpressionTerms(expression, binaryExpression.Left, binaryExpression.Right, terms, ref expressionType);
                return;
            }

            if (expression is AssignmentExpressionSyntax)
            {
                var assignmentExpression = (AssignmentExpressionSyntax)expression;
                AddBinaryExpressionTerms(expression, assignmentExpression.Left, assignmentExpression.Right, terms, ref expressionType);
                return;
            }

            if (expression is ConditionalExpressionSyntax)
            {
                AddConditionalExpressionTerms((ConditionalExpressionSyntax)expression, terms, ref expressionType);
                return;
            }

            var parenthesizedExpression = expression as ParenthesizedExpressionSyntax;
            if (parenthesizedExpression != null)
//.........这里部分代码省略.........
开发者ID:vslsnap,项目名称:roslyn,代码行数:101,代码来源:CSharpProximityExpressionsService_ExpressionTermCollector.cs


注:本文中的ExpressionSyntax.Kind方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。