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


C# ExpressionSyntax类代码示例

本文整理汇总了C#中ExpressionSyntax的典型用法代码示例。如果您正苦于以下问题:C# ExpressionSyntax类的具体用法?C# ExpressionSyntax怎么用?C# ExpressionSyntax使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: IsComplexExpression

 public static bool IsComplexExpression(ExpressionSyntax expr)
 {
     var loc = expr.GetLocation().GetLineSpan();
     return loc.StartLinePosition.Line != loc.EndLinePosition.Line ||
         expr is ConditionalExpressionSyntax ||
         expr is BinaryExpressionSyntax;
 }
开发者ID:Kavignon,项目名称:RefactoringEssentials,代码行数:7,代码来源:ConvertIfStatementToConditionalTernaryExpressionAnalyzer.cs

示例2: IsExpectedActualAssertion

        private static bool IsExpectedActualAssertion(ExpressionSyntax expression)
        {
            var expr = expression as MemberAccessExpressionSyntax;
            if (expr == null)
            {
                return false;
            }

            var identifier = expr.Expression as IdentifierNameSyntax;
            if (identifier == null)
            {
                return false;
            }

            if (identifier.Identifier.Text != "Assert")
            {
                return false;
            }

            var methodName = expr.Name.Identifier.Text;

            if (methodName == "Equal"  // Xunit
                || methodName == "AreEqual"  // NUnit, MSTest
                || methodName == "NotEqual"  // Xunit
                || methodName == "AreNotEqual"  // NUnit, MSTest
                )
            {
                return true;
            }

            return false;
        }
开发者ID:itowlson,项目名称:unexpected,代码行数:32,代码来源:DiagnosticAnalyzer.cs

示例3: CheckExpression

 private static bool CheckExpression(ExpressionSyntax constant, ExpressionSyntax modulus,
     out int constantValue)
 {
     return SillyBitwiseOperation.TryGetConstantIntValue(constant, out constantValue) &&
            constantValue != 0 &&
            ExpressionIsModulus(modulus);
 }
开发者ID:OsirisTerje,项目名称:sonarlint-vs,代码行数:7,代码来源:EqualityCheckOnModulus.cs

示例4: ArrayNameVerification

 internal static void ArrayNameVerification(ExpressionSyntax nameTree, string arrayName, int numRanks)
 {
     Assert.IsType(typeof(ArrayTypeSyntax), nameTree);
     var arrayType = nameTree as ArrayTypeSyntax;
     Assert.Equal(arrayType.ElementType.ToString(), arrayName);
     Assert.Equal(arrayType.RankSpecifiers.Count(), numRanks);
 }
开发者ID:EkardNT,项目名称:Roslyn,代码行数:7,代码来源:NodeValidators.cs

示例5: IsTypeApparentInAssignmentExpression

        /// <summary>
        /// Analyzes if type information is obvious to the reader by simply looking at the assignment expression.
        /// </summary>
        /// <remarks>
        /// <paramref name="typeInDeclaration"/> accepts null, to be able to cater to codegen features
        /// that are about to generate a local declaration and do not have this information to pass in.
        /// Things (like analyzers) that do have a local declaration already, should pass this in.
        /// </remarks>
        public static bool IsTypeApparentInAssignmentExpression(
            TypeStylePreference stylePreferences,
            ExpressionSyntax initializerExpression,
            SemanticModel semanticModel,
            CancellationToken cancellationToken,
            ITypeSymbol typeInDeclaration = null)
        {
            // default(type)
            if (initializerExpression.IsKind(SyntaxKind.DefaultExpression))
            {
                return true;
            }

            // literals, use var if options allow usage here.
            if (initializerExpression.IsAnyLiteralExpression())
            {
                return stylePreferences.HasFlag(TypeStylePreference.ImplicitTypeForIntrinsicTypes);
            }

            // constructor invocations cases:
            //      = new type();
            if (initializerExpression.IsKind(SyntaxKind.ObjectCreationExpression) &&
                !initializerExpression.IsKind(SyntaxKind.AnonymousObjectCreationExpression))
            {
                return true;
            }

            // explicit conversion cases: 
            //      (type)expr, expr is type, expr as type
            if (initializerExpression.IsKind(SyntaxKind.CastExpression) ||
                initializerExpression.IsKind(SyntaxKind.IsExpression) ||
                initializerExpression.IsKind(SyntaxKind.AsExpression))
            {
                return true;
            }

            // other Conversion cases:
            //      a. conversion with helpers like: int.Parse methods
            //      b. types that implement IConvertible and then invoking .ToType()
            //      c. System.Convert.Totype()
            var memberName = GetRightmostInvocationExpression(initializerExpression).GetRightmostName();
            if (memberName == null)
            {
                return false;
            }

            var methodSymbol = semanticModel.GetSymbolInfo(memberName, cancellationToken).Symbol as IMethodSymbol;
            if (methodSymbol == null)
            {
                return false;
            }

            if (memberName.IsRightSideOfDot())
            {
                var containingTypeName = memberName.GetLeftSideOfDot();
                return IsPossibleCreationOrConversionMethod(methodSymbol, typeInDeclaration, semanticModel, containingTypeName, cancellationToken);
            }

            return false;
        }
开发者ID:Rickinio,项目名称:roslyn,代码行数:68,代码来源:TypeStyleHelper.cs

示例6: IsTypeWithInefficientLinqMethods

        /// <summary>
        /// The Enumerable.Last method will only special case indexable types that implement <see cref="IList{T}" />.  Types 
        /// which implement only <see cref="IReadOnlyList{T}"/> will be treated the same as IEnumerable{T} and go through a 
        /// full enumeration.  This method identifies such types.
        /// 
        /// At this point it only identifies <see cref="IReadOnlyList{T}"/> directly but could easily be extended to support
        /// any type which has an index and count property.  
        /// </summary>
        private bool IsTypeWithInefficientLinqMethods(SyntaxNodeAnalysisContext context, ExpressionSyntax targetSyntax, ITypeSymbol readonlyListType, ITypeSymbol listType)
        {
            var targetTypeInfo = context.SemanticModel.GetTypeInfo(targetSyntax);
            if (targetTypeInfo.Type == null)
            {
                return false;
            }

            var targetType = targetTypeInfo.Type;

            // If this type is simply IReadOnlyList<T> then no further checking is needed.  
            if (targetType.TypeKind == TypeKind.Interface && targetType.OriginalDefinition.Equals(readonlyListType))
            {
                return true;
            }

            bool implementsReadOnlyList = false;
            bool implementsList = false;
            foreach (var current in targetType.AllInterfaces)
            {
                if (current.OriginalDefinition.Equals(readonlyListType))
                {
                    implementsReadOnlyList = true;
                }

                if (current.OriginalDefinition.Equals(listType))
                {
                    implementsList = true;
                }
            }

            return implementsReadOnlyList && !implementsList;
        }
开发者ID:ehsansajjad465,项目名称:roslyn,代码行数:41,代码来源:LinqAnalyzer.cs

示例7: GetTypes

            // TODO: Add support for Expression<T>
            private IEnumerable<ITypeSymbol> GetTypes(ExpressionSyntax expression)
            {
                if (seenExpressionGetType.Add(expression))
                {
                    IEnumerable<ITypeSymbol> types;

                    // BUG: (vladres) Are following expressions parenthesized correctly?
                    // BUG:
                    // BUG: (davip) It is parenthesized incorrectly. This problem was introduced in Changeset 822325 when 
                    // BUG: this method was changed from returning a single ITypeSymbol to returning an IEnumerable<ITypeSymbol> 
                    // BUG: to better deal with overloads. The old version was:
                    // BUG: 
                    // BUG:     if (!IsUnusableType(type = GetTypeSimple(expression)) ||
                    // BUG:         !IsUnusableType(type = GetTypeComplex(expression)))
                    // BUG:           { return type; }
                    // BUG: 
                    // BUG: The intent is to only use *usable* types, whether simple or complex. I have confirmed this intent with Ravi, who made the change. 
                    // BUG: 
                    // BUG: Note that the current implementation of GetTypesComplex and GetTypesSimple already ensure the returned value 
                    // BUG: is a usable type, so there should not (currently) be any observable effect of this logic error.
                    // BUG:
                    // BUG: (vladres) Please remove this comment once the bug is fixed.
                    if ((types = GetTypesSimple(expression).Where(t => !IsUnusableType(t))).Any() ||
                        (types = GetTypesComplex(expression)).Where(t => !IsUnusableType(t)).Any())
                    {
                        return types;
                    }
                }

                return SpecializedCollections.EmptyEnumerable<ITypeSymbol>();
            }
开发者ID:jerriclynsjohn,项目名称:roslyn,代码行数:32,代码来源:CSharpTypeInferenceService.TypeInferrer.cs

示例8: IsCorrectReturnType

 private bool IsCorrectReturnType(ExpressionSyntax expression, SemanticModel semanticModel)
 {
     INamedTypeSymbol taskType = null;
     INamedTypeSymbol returnType = null;
     return TryGetTypes(expression, semanticModel, out taskType, out returnType) &&
     semanticModel.Compilation.ClassifyConversion(taskType, returnType).Exists;
 }
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:7,代码来源:CSharpAddAwaitCodeFixProvider.cs

示例9: FindSymbol

        private INamedTypeSymbol FindSymbol(ExpressionSyntax expression)
        {
            while (true)
            {
                var parenthesizedExpression = expression as ParenthesizedExpressionSyntax;
                if (parenthesizedExpression != null)
                {
                    expression = parenthesizedExpression.Expression;
                    continue;
                }

                var castExpression = expression as CastExpressionSyntax;
                if (castExpression != null)
                {
                    return semanticModel.GetTypeInfo(castExpression.Type).Type as INamedTypeSymbol;
                }

                if (expression is InvocationExpressionSyntax)//Handled by invocationanalzyer
                {
                    return null;
                }

                var localSymbol = semanticModel.GetSymbolInfo(expression).Symbol as ILocalSymbol;
                return localSymbol?.Type as INamedTypeSymbol;
            }
        }
开发者ID:hvanbakel,项目名称:Asyncify-CSharp,代码行数:26,代码来源:VariableAccessChecker.cs

示例10: AddIsNaNIssue

 static CodeAction AddIsNaNIssue(Document document, SemanticModel semanticModel, SyntaxNode root, BinaryExpressionSyntax node, ExpressionSyntax argExpr, string floatType)
 {
     return CodeActionFactory.Create(node.Span, DiagnosticSeverity.Warning, string.Format(node.IsKind(SyntaxKind.EqualsExpression) ? "Replace with '{0}.IsNaN(...)' call" : "Replace with '!{0}.IsNaN(...)' call", floatType), token =>
     {
         SyntaxNode newRoot;
         ExpressionSyntax expr;
         var arguments = new SeparatedSyntaxList<ArgumentSyntax>();
         arguments = arguments.Add(SyntaxFactory.Argument(argExpr));
         expr = SyntaxFactory.InvocationExpression(
             SyntaxFactory.MemberAccessExpression(
                 SyntaxKind.SimpleMemberAccessExpression,
                 SyntaxFactory.ParseExpression(floatType),
                 SyntaxFactory.IdentifierName("IsNaN")
             ),
             SyntaxFactory.ArgumentList(
                 arguments
             )
         );
         if (node.IsKind(SyntaxKind.NotEqualsExpression))
             expr = SyntaxFactory.PrefixUnaryExpression(SyntaxKind.LogicalNotExpression, expr);
         expr = expr.WithAdditionalAnnotations(Formatter.Annotation);
         newRoot = root.ReplaceNode((SyntaxNode)node, expr);
         return Task.FromResult(document.WithSyntaxRoot(newRoot));
     });
 }
开发者ID:Kavignon,项目名称:RefactoringEssentials,代码行数:25,代码来源:CompareOfFloatsByEqualityOperatorCodeFixProvider.cs

示例11: QueryUnboundLambdaState

 public QueryUnboundLambdaState(UnboundLambda unbound, Binder binder, RangeVariableMap rangeVariableMap, ImmutableArray<RangeVariableSymbol> parameters, ExpressionSyntax body)
     : this(unbound, binder, rangeVariableMap, parameters, (LambdaSymbol lambdaSymbol, ExecutableCodeBinder lambdaBodyBinder, DiagnosticBag diagnostics) =>
 {
     BoundExpression expression = lambdaBodyBinder.BindValue(body, diagnostics, BindValueKind.RValue);
     return lambdaBodyBinder.WrapExpressionLambdaBody(expression, body, diagnostics);
 })
 { }
开发者ID:riversky,项目名称:roslyn,代码行数:7,代码来源:Binder.QueryUnboundLambdaState.cs

示例12: Resolve

        public override FlatOperand Resolve(ExpressionSyntax expression, ArgumentListSyntax argumentList, TypeInfo result_type, SymbolInfo si, FlatOperand into_lvalue, Function function, List<FlatStatement> instructions)
        {
            FlatOperand fop_subject;
            if (expression is IdentifierNameSyntax)
            {
                // typeof this
                fop_subject = FlatOperand.ThisRef(FlatValue.FromType(result_type.ConvertedType));
            }
            else if (expression is MemberAccessExpressionSyntax)
            {
                MemberAccessExpressionSyntax meas = (MemberAccessExpressionSyntax)expression;

                fop_subject = function.ResolveExpression(meas.Expression, null, instructions);
            }
            else
            {
                throw new NotImplementedException("GetMetaTable on expression type " + expression.GetType().ToString());
            }

            if (into_lvalue == null)
            {
                FlatOperand fop_register = function.AllocateRegister("");
                into_lvalue = fop_register.GetLValue(function, instructions);
            }
            instructions.Add(FlatStatement.GETMETATABLE(into_lvalue, fop_subject));
            return into_lvalue.AsRValue(FlatValue.Table());
        }
开发者ID:LaxLacks,项目名称:ls2csc,代码行数:27,代码来源:Intrinsics.cs

示例13: 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

示例14: IsComplexCondition

        public static bool IsComplexCondition(ExpressionSyntax expr)
        {
            var loc = expr.GetLocation().GetLineSpan();
            if (loc.StartLinePosition.Line != loc.EndLinePosition.Line)
                return true;

            if (expr is LiteralExpressionSyntax || expr is IdentifierNameSyntax || expr is MemberAccessExpressionSyntax || expr is InvocationExpressionSyntax)
                return false;

            var pexpr = expr as ParenthesizedExpressionSyntax;
            if (pexpr != null)
                return IsComplexCondition(pexpr.Expression);

            var uOp = expr as PrefixUnaryExpressionSyntax;
            if (uOp != null)
                return IsComplexCondition(uOp.Operand);

            var bop = expr as BinaryExpressionSyntax;
            if (bop == null)
                return true;
            return !(bop.IsKind(SyntaxKind.GreaterThanExpression) ||
                bop.IsKind(SyntaxKind.GreaterThanOrEqualExpression) ||
                bop.IsKind(SyntaxKind.EqualsExpression) ||
                bop.IsKind(SyntaxKind.NotEqualsExpression) ||
                bop.IsKind(SyntaxKind.LessThanExpression) ||
                bop.IsKind(SyntaxKind.LessThanOrEqualExpression));
        }
开发者ID:Kavignon,项目名称:RefactoringEssentials,代码行数:27,代码来源:ConvertIfStatementToConditionalTernaryExpressionAnalyzer.cs

示例15: GetTypesSimple

            private IEnumerable<ITypeSymbol> GetTypesSimple(ExpressionSyntax expression)
            {
                if (expression != null)
                {
                    var typeInfo = SemanticModel.GetTypeInfo(expression, CancellationToken);
                    var symbolInfo = SemanticModel.GetSymbolInfo(expression, CancellationToken);

                    if (symbolInfo.CandidateReason != CandidateReason.WrongArity)
                    {
                        ITypeSymbol type = typeInfo.Type;

                        // If it bound to a method, try to get the Action/Func form of that method.
                        if (type == null &&
                            symbolInfo.GetAllSymbols().Count() == 1 &&
                            symbolInfo.GetAllSymbols().First().Kind == SymbolKind.Method)
                        {
                            var method = symbolInfo.GetAllSymbols().First();
                            type = method.ConvertToType(this.Compilation);
                        }

                        if (IsUsableTypeFunc(type))
                        {
                            return SpecializedCollections.SingletonEnumerable(type);
                        }
                    }
                }

                return SpecializedCollections.EmptyEnumerable<ITypeSymbol>();
            }
开发者ID:nileshjagtap,项目名称:roslyn,代码行数:29,代码来源:CSharpTypeInferenceService.TypeInferrer.cs


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