• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# InvocationExpressionSyntax类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: VisitInvocationExpression

        public override void VisitInvocationExpression(InvocationExpressionSyntax node)
        {
            var symbol = (IMethodSymbol)SemanticModel.GetSymbolInfo(node).Symbol;

            if (symbol != null)
            {
                Enums.AsyncDetected type = DetectCPUAsynchronousUsages(node,symbol);
                Result.StoreDetectedCPUAsyncUsage(type);

                // Check whether there are some blocking operations under task, threadpool, and thread!
                //if (type == Enums.AsyncDetected.Task || type == Enums.AsyncDetected.Threadpool || type == Enums.AsyncDetected.Thread)
                //{
                //    foreach (var methodCall in node.DescendantNodes().OfType<InvocationExpressionSyntax>())
                //    {
                //        var methodCallSymbol = (IMethodSymbol)SemanticModel.GetSymbolInfo(methodCall).Symbol;

                //        if (methodCallSymbol != null)
                //        {
                //            var synctype = ((IMethodSymbol)methodCallSymbol.OriginalDefinition).DetectSynchronousUsages(SemanticModel);

                //            if (synctype != Utilities.Enums.SyncDetected.None)
                //                Logs.TempLog.Info("LONGRUNNING {0} {1}{2}--------------------------", methodCallSymbol, Document.FilePath, node.ToLog());
                //        }
                //    }
                //}

            }

            base.VisitInvocationExpression(node);
        }
开发者ID:modulexcite,项目名称:concurrent-code-analyses,代码行数:30,代码来源:CPUAsyncDetectionWalker.cs


示例2: VisitInvocationExpression

        public override void VisitInvocationExpression(InvocationExpressionSyntax node)
        {
            var symbol = (IMethodSymbol)SemanticModel.GetSymbolInfo(node).Symbol;
            
            if (symbol != null)
            {
                var type = DetectIOAsynchronousUsages(node, symbol);
                Result.StoreDetectedIOAsyncUsage(type);

                //DetectBlockingOperations(node, symbol);

                //if (type == Enums.AsyncDetected.EAP)
                //    Logs.TempLog2.Info("{0}{1}*****************************************", Document.FilePath, node.FirstAncestorOrSelf<MethodDeclarationSyntax>().ToLog());

                if (type == Enums.AsyncDetected.TAP)
                    //Logs.TempLog3.Info("{0}{1}*****************************************", Document.FilePath, node.FirstAncestorOrSelf<MethodDeclarationSyntax>().ToLog());
                    Logs.TempLog3.Info("{0}", symbol);

                //if (type == Enums.AsyncDetected.APM)
                //    Logs.TempLog4.Info("{0}{1}*****************************************", Document.FilePath, node.FirstAncestorOrSelf<MethodDeclarationSyntax>().ToLog());

            }

            base.VisitInvocationExpression(node);
        }
开发者ID:modulexcite,项目名称:concurrent-code-analyses,代码行数:25,代码来源:AsyncAwaitDetectionWalker.cs


示例3: FindAsyncStateInvocationArgument

        public static ArgumentSyntax FindAsyncStateInvocationArgument(InvocationExpressionSyntax apmSyntax, IMethodSymbol apmSymbol)
        {
            var parameterIndex = FindMethodParameterIndex(apmSymbol, "object", "state");
            var callbackArgument = apmSyntax.ArgumentList.Arguments.ElementAt(parameterIndex);

            return callbackArgument;
        }
开发者ID:modulexcite,项目名称:Asyncifier,代码行数:7,代码来源:CodeRefactoringProvider.cs


示例4: MakeUppercaseAsync

		async Task<Document> MakeUppercaseAsync(Document document, InvocationExpressionSyntax invocation,
			CancellationToken cancellationToken)
		{
			var semanticModel = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false);
			var typeSymbol = semanticModel.GetSymbolInfo(invocation.Expression, cancellationToken).Symbol;
			var nfluentCheck = semanticModel.Compilation.NFluentCheckType();

			if (typeSymbol == null || nfluentCheck == null) return document;

			var newMethod = typeSymbol.Name == "AreEqual" ? "IsEqualTo" : "IsNotEqualTo";

			var checkThat = CheckThat(nfluentCheck, invocation.ArgumentList.Arguments[1]);

			var replacement = InvocationExpression(
				MemberAccessExpression(
					SyntaxKind.SimpleMemberAccessExpression,
					checkThat,
					IdentifierName(newMethod)),
				ArgumentList(SingletonSeparatedList(invocation.ArgumentList.Arguments[0])))
				.WithTriviaFrom(invocation);

			var syntaxRoot = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);
			var newSyntaxRoot = syntaxRoot.ReplaceNode(invocation, replacement);
			var newDocument = document.WithSyntaxRoot(newSyntaxRoot);

			var withUsings = await UsingHelpers.AddUsingsAsync(newDocument, replacement, cancellationToken,
				nfluentCheck.ContainingNamespace);

			return withUsings;
		}
开发者ID:vbfox,项目名称:NFluentConversion,代码行数:30,代码来源:ReplaceNUnitCodeFix.cs


示例5: GetDelegateInvokeItems

        private IEnumerable<SignatureHelpItem> GetDelegateInvokeItems(
            InvocationExpressionSyntax invocationExpression, SemanticModel semanticModel, ISymbolDisplayService symbolDisplayService, IAnonymousTypeDisplayService anonymousTypeDisplayService,
            IDocumentationCommentFormattingService documentationCommentFormattingService, ISymbol within, INamedTypeSymbol delegateType, CancellationToken cancellationToken)
        {
            var invokeMethod = delegateType.DelegateInvokeMethod;
            if (invokeMethod == null)
            {
                return null;
            }

            // Events can only be invoked directly from the class they were declared in.
            var expressionSymbol = semanticModel.GetSymbolInfo(invocationExpression.Expression, cancellationToken).GetAnySymbol();
            if (expressionSymbol.IsKind(SymbolKind.Event) &&
                !expressionSymbol.ContainingType.OriginalDefinition.Equals(within.OriginalDefinition))
            {
                return null;
            }

            var position = invocationExpression.SpanStart;
            var item = CreateItem(
                invokeMethod, semanticModel, position,
                symbolDisplayService, anonymousTypeDisplayService,
                isVariadic: invokeMethod.IsParams(),
                documentation: SpecializedCollections.EmptyEnumerable<SymbolDisplayPart>(),
                prefixParts: GetDelegateInvokePreambleParts(invokeMethod, semanticModel, position),
                separatorParts: GetSeparatorParts(),
                suffixParts: GetDelegateInvokePostambleParts(),
                parameters: GetDelegateInvokeParameters(invokeMethod, semanticModel, position, documentationCommentFormattingService, cancellationToken));

            return SpecializedCollections.SingletonEnumerable(item);
        }
开发者ID:JinGuoGe,项目名称:roslyn,代码行数:31,代码来源:InvocationExpressionSignatureHelpProvider_DelegateInvoke.cs


示例6: ConvertToInterpolatedString

        private Task<Document> ConvertToInterpolatedString(Document document, SyntaxNode root, InvocationExpressionSyntax invocation, CancellationToken cancellationToken)
        {
            string previousString = null;
            var parts = new List<InterpolatedStringContentSyntax>(invocation.ArgumentList.Arguments.Count);
            for (int i = 0; i < invocation.ArgumentList.Arguments.Count; i++)
            {
                ArgumentSyntax argument = invocation.ArgumentList.Arguments[i];
                var literal = argument.Expression as LiteralExpressionSyntax;

                if (literal?.IsKind(SyntaxKind.StringLiteralExpression) ?? false)
                {
                    //strings needs to be collapsed, otherwise VS will insert additional whitespaces
                    previousString += literal.Token.Text.Substring(1, literal.Token.Text.Length - 2);
                }
                else
                {
                    if (previousString != null)
                    {
                        parts.Add(InterpolatedStringGenerator.TextPart(previousString));
                        previousString = null;
                    }
                    parts.Add(InterpolatedStringGenerator.ExpressionPart(argument.Expression.WithoutLeadingTrivia().WithoutTrailingTrivia()));
                }
            }
            if (previousString != null)
            {
                parts.Add(InterpolatedStringGenerator.TextPart(previousString));
            }

            SyntaxNode interpolated = InterpolatedStringGenerator.InterpolatedString(parts);

            root = root.ReplaceNode(invocation, interpolated);

            return Task.FromResult(document.WithSyntaxRoot(root));
        }
开发者ID:Suchiman,项目名称:RoslynRefactorings,代码行数:35,代码来源:CodeRefactoringProvider.cs


示例7: VisitInvocationExpression

        public override SyntaxNode VisitInvocationExpression(InvocationExpressionSyntax node)
        {
            // Replace the module method name with a qualified one if this is a module ctor
            bool nodeChanged = IsInvocationAModuleCtor(node);
            ExpressionSyntax nodeExpression = nodeChanged
                ? ((IdentifierNameSyntax)node.Expression).WithIdentifier(
                    SyntaxFactory.Identifier("ConfigScript." + ((IdentifierNameSyntax)node.Expression).Identifier.Text)
                        .WithTriviaFrom(((IdentifierNameSyntax)node.Expression).Identifier))
                : node.Expression;

            // Get a hash of all the previous @doc and @ctx lambda parameters and don't replace the same
            HashSet<string> currentScopeLambdaParameters = new HashSet<string>(
                node.Ancestors().OfType<LambdaExpressionSyntax>().SelectMany(
                    x => x.DescendantNodes().OfType<ParameterSyntax>()).Select(x => x.Identifier.Text));

            // Only do the replacement if this is a module ctor or a module fluent method
            ArgumentListSyntax argumentList = node.ArgumentList;
            if(nodeChanged || IsInvocationAFluentMethod(node))
            {
                // Replace @doc and @ctx argument expressions with the appropriate lambda expressions, and stop descending if we hit another module ctor
                foreach (ArgumentSyntax argument in node.ArgumentList.Arguments)
                {
                    // Don't replace existing lambda expressions
                    if (!(argument.Expression is LambdaExpressionSyntax))
                    {
                        List<IdentifierNameSyntax> identifierNames = argument
                            .DescendantNodes(x => !(x is InvocationExpressionSyntax) || !IsInvocationAModuleCtorOrFluentMethod((InvocationExpressionSyntax)x))
                            .OfType<IdentifierNameSyntax>()
                            .Where(x => x != null && !currentScopeLambdaParameters.Contains(x.Identifier.Text))
                            .ToList();
                        IdentifierNameSyntax docReplacementName = identifierNames.FirstOrDefault(x => x.Identifier.Text.StartsWith("@doc"));
                        IdentifierNameSyntax ctxReplacementName = identifierNames.FirstOrDefault(x => x.Identifier.Text.StartsWith("@ctx"));
                        if (docReplacementName != null)
                        {
                            argumentList = argumentList.ReplaceNode(argument, SyntaxFactory.Argument(
                                SyntaxFactory.ParenthesizedLambdaExpression(
                                    SyntaxFactory.ParameterList(
                                        new SeparatedSyntaxList<ParameterSyntax>()
                                            .Add(SyntaxFactory.Parameter(SyntaxFactory.Identifier(docReplacementName.Identifier.Text)))
                                            .Add(SyntaxFactory.Parameter(SyntaxFactory.Identifier(ctxReplacementName == null ? "_" : ctxReplacementName.Identifier.Text)))),
                                    argument.Expression))
                                .WithTriviaFrom(argument));
                            nodeChanged = true;
                        }
                        else if (ctxReplacementName != null)
                        {
                            argumentList = argumentList.ReplaceNode(argument, SyntaxFactory.Argument(
                                SyntaxFactory.SimpleLambdaExpression(
                                    SyntaxFactory.Parameter(SyntaxFactory.Identifier(ctxReplacementName.Identifier.Text)),
                                    argument.Expression))
                                .WithTriviaFrom(argument));
                            nodeChanged = true;
                        }
                    }
                }
            }

            // Build and return the result node (or just return the original node)
            return base.VisitInvocationExpression(nodeChanged ? node.WithExpression(nodeExpression).WithArgumentList(argumentList) : node);
        }
开发者ID:martinvobr,项目名称:Wyam,代码行数:60,代码来源:ConfigRewriter.cs


示例8: VisitInvocationExpression

        public override void VisitInvocationExpression(InvocationExpressionSyntax node)
        {
            var symbol = (IMethodSymbol)SemanticModel.GetSymbolInfo(node).Symbol;

            if (symbol != null)
            {
                if(symbol.ToString().Contains("System.Threading.Tasks.Task.WaitAll"))
                {
                    var block = node.Ancestors().OfType<BlockSyntax>().First();

                    if (block.DescendantNodes().OfType<ForEachStatementSyntax>().Any() || block.DescendantNodes().OfType<ForStatementSyntax>().Any())
                        return;
                    foreach (var invocation in block.DescendantNodes().OfType<InvocationExpressionSyntax>())
                    {
                        var symbol2 = (IMethodSymbol)SemanticModel.GetSymbolInfo(invocation).Symbol;
                        if (symbol2!=null && symbol2.IsTaskCreationMethod())
                        {
                            Logs.TempLog3.Info("{0}{1}--------------------------", Document.FilePath, block.ToLog());
                            break;
                        }
                    }
                    
                }

            }


            base.VisitInvocationExpression(node);
        }
开发者ID:modulexcite,项目名称:concurrent-code-analyses,代码行数:29,代码来源:SimplifierDetectionWalker.cs


示例9: CheckIsInstanceOfTypeCallWithTypeArgument

        private static void CheckIsInstanceOfTypeCallWithTypeArgument(InvocationExpressionSyntax invocation, IMethodSymbol methodSymbol,
            SyntaxNodeAnalysisContext context)
        {
            if (methodSymbol.Name != "IsInstanceOfType" ||
                !methodSymbol.ContainingType.Is(KnownType.System_Type) ||
                !invocation.HasExactlyNArguments(1))
            {
                return;
            }

            var argument = invocation.ArgumentList.Arguments.First().Expression;

            var typeInfo = context.SemanticModel.GetTypeInfo(argument).Type;
            if (!typeInfo.Is(KnownType.System_Type))
            {
                return;
            }

            var invocationInArgument = argument as InvocationExpressionSyntax;
            var message = IsGetTypeCall(invocationInArgument, context.SemanticModel)
                ? MessageIsInstanceOfTypeWithGetType
                : MessageIsInstanceOfType;

            context.ReportDiagnostic(Diagnostic.Create(Rule, argument.GetLocation(), message));
        }
开发者ID:duncanpMS,项目名称:sonarlint-vs,代码行数:25,代码来源:TypeExaminationOnSystemType.cs


示例10: CreateInterpolatedString

        private async Task<Document> CreateInterpolatedString(InvocationExpressionSyntax invocation, Document document, CancellationToken cancellationToken)
        {
            Assert(invocation.ArgumentList != null);
            Assert(invocation.ArgumentList.Arguments.Count >= 2);
            Assert(invocation.ArgumentList.Arguments[0].Expression.IsKind(SyntaxKind.StringLiteralExpression));

            var semanticModel = await document.GetSemanticModelAsync(cancellationToken);

            var arguments = invocation.ArgumentList.Arguments;
            var text = ((LiteralExpressionSyntax)arguments[0].Expression).Token.ToString();

            var builder = ImmutableArray.CreateBuilder<ExpressionSyntax>();
            for (int i = 1; i < arguments.Count; i++)
            {
                builder.Add(CastAndParenthesize(arguments[i].Expression, semanticModel));
            }

            var expandedArguments = builder.ToImmutable();

            var interpolatedString = (InterpolatedStringExpressionSyntax)SyntaxFactory.ParseExpression("$" + text);

            var newInterpolatedString = InterpolatedStringRewriter.Visit(interpolatedString, expandedArguments);

            var root = await document.GetSyntaxRootAsync(cancellationToken);
            var newRoot = root.ReplaceNode(invocation, newInterpolatedString);

            return document.WithSyntaxRoot(newRoot);
        }
开发者ID:Killerameise,项目名称:CSharpEssentials,代码行数:28,代码来源:ConvertToInterpolatedStringRefactoring.cs


示例11: PerformAction

        static Document PerformAction(Document document, SyntaxNode root, InvocationExpressionSyntax invocationNode)
        {
            var arg = invocationNode.ArgumentList.Arguments.Select(a => a.Expression).First();
            if (!arg.DescendantNodesAndSelf().OfType<BinaryExpressionSyntax>().All(bop => bop.IsKind(SyntaxKind.BitwiseOrExpression)))
                return document;

            arg = ConvertBitwiseFlagComparisonToHasFlagsCodeRefactoringProvider.MakeFlatExpression(arg, SyntaxKind.BitwiseAndExpression);
            if (arg is BinaryExpressionSyntax)
                arg = SyntaxFactory.ParenthesizedExpression(arg);

            SyntaxNode nodeToReplace = invocationNode;
            while (nodeToReplace.Parent is ParenthesizedExpressionSyntax)
                nodeToReplace = nodeToReplace.Parent;

            bool negateHasFlags = nodeToReplace.Parent != null && nodeToReplace.Parent.IsKind(SyntaxKind.LogicalNotExpression);
            if (negateHasFlags)
                nodeToReplace = nodeToReplace.Parent;

            var expr = SyntaxFactory.BinaryExpression(
                negateHasFlags ? SyntaxKind.EqualsExpression : SyntaxKind.NotEqualsExpression,
                SyntaxFactory.ParenthesizedExpression(SyntaxFactory.BinaryExpression(SyntaxKind.BitwiseAndExpression, ((MemberAccessExpressionSyntax)invocationNode.Expression).Expression, arg))
                .WithAdditionalAnnotations(Formatter.Annotation),
                SyntaxFactory.ParseExpression("0")
            );

            var newRoot = root.ReplaceNode((SyntaxNode)
                nodeToReplace,
                expr.WithAdditionalAnnotations(Formatter.Annotation)
            );
            return document.WithSyntaxRoot(newRoot);
        }
开发者ID:alecor191,项目名称:RefactoringEssentials,代码行数:31,代码来源:ConvertHasFlagsToBitwiseFlagComparisonCodeRefactoringProvider.cs


示例12: CreateRelacementNode

        /// <summary>
        /// Creates a new ExpressionSyntax to replace the defaultIfNull InvocationExpressionSyntax
        /// </summary>
        public static ExpressionSyntax CreateRelacementNode(InvocationExpressionSyntax defaultIfNullexpression)
        {
            // We should change from  x.DefaultIfNull(y => y.z...)  or  x.DefaultIfNull(y => y.[..]...)
            //                  into  x?.z...                           x?[..]...

            // Get the expression on which DefaultIfNull is invoked, this is the x
            var rootExpression = (defaultIfNullexpression.Expression as MemberAccessExpressionSyntax)?.Expression;

            // Get the first parameter to DefaultIfNull, this is the Lambda y => y.z...
            var lambda = GetLambdaFromFirstArgument(defaultIfNullexpression);
            if (lambda == null) return defaultIfNullexpression;

            // Get the MemberAccessExpression y.z or ElementAccessExpression y[..] from the lamba body
            var accessExpression = GetLeftMostAccessExpression(lambda);
            if (accessExpression == null) return defaultIfNullexpression;

            // A ConditionalAccessExpression requires a ..BindingExpression instead of the ..AccessExpression
            var bindingExpression = ToBindingExpression(accessExpression);

            // Replace the AccessExpression from the Labmda body with the BindingExpression this will result in the .z... or [..]... part
            var whenNotNullExpression = (ExpressionSyntax)lambda.Body.ReplaceNode(accessExpression, bindingExpression)
                                                                        .WithTriviaFrom(accessExpression);

            // Combine the x and .z... into x?.z...
            return SyntaxFactory.ConditionalAccessExpression(
                expression: rootExpression,
                whenNotNull: whenNotNullExpression).WithTriviaFrom(defaultIfNullexpression);
        }
开发者ID:FrankBakkerNl,项目名称:DefaultIfNullAnalyser,代码行数:31,代码来源:DefaulIfNullExpressionHelper.cs


示例13: RewriteStatement

        /// <summary>
        /// Rewrites the statement with a monitor statement.
        /// </summary>
        /// <param name="node">LocalDeclarationStatementSyntax</param>
        /// <returns>StatementSyntax</returns>
        private SyntaxNode RewriteStatement(InvocationExpressionSyntax node)
        {
            var arguments = new List<ArgumentSyntax>();
            arguments.Add(node.ArgumentList.Arguments[0]);

            string payload = "";
            for (int i = 1; i < node.ArgumentList.Arguments.Count; i++)
            {
                if (i == node.ArgumentList.Arguments.Count - 1)
                {
                    payload += node.ArgumentList.Arguments[i].ToString();
                }
                else
                {
                    payload += node.ArgumentList.Arguments[i].ToString() + ", ";
                }
            }

            arguments[0] = SyntaxFactory.Argument(SyntaxFactory.ParseExpression(
                "new " + arguments[0].ToString() + "(" + payload + ")"));

            var rewritten = node.
                WithArgumentList(SyntaxFactory.ArgumentList(SyntaxFactory.SeparatedList(arguments))).
                WithExpression((node.Expression as GenericNameSyntax).
                WithIdentifier(SyntaxFactory.Identifier("this.Monitor"))).
                WithTriviaFrom(node);

            return rewritten;
        }
开发者ID:yonglehou,项目名称:PSharp,代码行数:34,代码来源:MonitorRewriter.cs


示例14: RemoveCall

 private static SyntaxNode RemoveCall(SyntaxNode root,
     InvocationExpressionSyntax castInvocation, MemberAccessExpressionSyntax memberAccess)
 {
     return castInvocation != null
         ? RemoveExtensionMethodCall(root, castInvocation)
         : RemoveStaticMemberCall(root, memberAccess);
 }
开发者ID:jakobehn,项目名称:sonarlint-vs,代码行数:7,代码来源:RedundantCastCodeFixProvider.cs


示例15: HasCheckForNullThatReturns

 private static bool HasCheckForNullThatReturns(InvocationExpressionSyntax invocation, SemanticModel semanticModel, ISymbol symbol)
 {
     var method = invocation.FirstAncestorOfKind(SyntaxKind.MethodDeclaration) as MethodDeclarationSyntax;
     if (method != null && method.Body != null)
     {
         var ifs = method.Body.Statements.OfKind(SyntaxKind.IfStatement);
         foreach (IfStatementSyntax @if in ifs)
         {
             if ([email protected]?.IsKind(SyntaxKind.EqualsExpression) ?? true) continue;
             var equals = (BinaryExpressionSyntax)@if.Condition;
             if (equals.Left == null || equals.Right == null) continue;
             if (@if.GetLocation().SourceSpan.Start > invocation.GetLocation().SourceSpan.Start) return false;
             ISymbol identifierSymbol;
             if (equals.Right.IsKind(SyntaxKind.NullLiteralExpression) && equals.Left.IsKind(SyntaxKind.IdentifierName))
                 identifierSymbol = semanticModel.GetSymbolInfo(equals.Left).Symbol;
             else if (equals.Left.IsKind(SyntaxKind.NullLiteralExpression) && equals.Right.IsKind(SyntaxKind.IdentifierName))
                 identifierSymbol = semanticModel.GetSymbolInfo(equals.Right).Symbol;
             else continue;
             if (!symbol.Equals(identifierSymbol)) continue;
             if (@if.Statement == null) continue;
             if (@if.Statement.IsKind(SyntaxKind.Block))
             {
                 var ifBlock = (BlockSyntax)@if.Statement;
                 if (ifBlock.Statements.OfKind(SyntaxKind.ThrowStatement, SyntaxKind.ReturnStatement).Any()) return true;
             }
             else
             {
                 if (@if.Statement.IsAnyKind(SyntaxKind.ThrowStatement, SyntaxKind.ReturnStatement)) return true;
             }
         }
     }
     return false;
 }
开发者ID:julianosaless,项目名称:code-cracker,代码行数:33,代码来源:UseInvokeMethodToFireEventAnalyzer.cs


示例16: AnalyzeInvocationExpression

            private void AnalyzeInvocationExpression(InvocationExpressionSyntax node, SemanticModel model, Action<Diagnostic> reportDiagnostic)
            {
                if (node.Expression.Kind() == SyntaxKind.SimpleMemberAccessExpression)
                {
                    var memberAccess = (MemberAccessExpressionSyntax)node.Expression;
                    if (memberAccess.Name != null && IsEqualsOrCompare(memberAccess.Name.Identifier.ValueText))
                    {
                        var methodSymbol = model.GetSymbolInfo(memberAccess.Name).Symbol as IMethodSymbol;
                        if (methodSymbol != null && methodSymbol.ContainingType.SpecialType == SpecialType.System_String)
                        {
                            Debug.Assert(IsEqualsOrCompare(methodSymbol.Name));

                            if (!IsAcceptableOverload(methodSymbol, model))
                            {
                                // wrong overload
                                reportDiagnostic(memberAccess.Name.GetLocation().CreateDiagnostic(Rule));
                            }
                            else
                            {
                                var lastArgument = node.ArgumentList.Arguments.Last();
                                var lastArgSymbol = model.GetSymbolInfo(lastArgument.Expression).Symbol;
                                if (lastArgSymbol != null && lastArgSymbol.ContainingType != null &&
                                    lastArgSymbol.ContainingType.Equals(StringComparisonType) &&
                                    !IsOrdinalOrOrdinalIgnoreCase(lastArgument, model))
                                {
                                    // right overload, wrong value
                                    reportDiagnostic(lastArgument.GetLocation().CreateDiagnostic(Rule));
                                }
                            }
                        }
                    }
                }
            }
开发者ID:maggiemsft,项目名称:roslyn-analyzers,代码行数:33,代码来源:CSharpUseOrdinalStringComparison.cs


示例17: ChangeToOneLiteral

        private async Task<Document> ChangeToOneLiteral(InvocationExpressionSyntax ex, Document document, CancellationToken cancellationToken)
        {
            var literal1 = ex.GetLiteralExpression();
            if (literal1 == null) return document;

            var literal2 = ex.GetLiteralArgument();
            if (literal2 == null) return document;

            var x = int.Parse(literal1.Token.ValueText);
            var y = int.Parse(literal2.Token.ValueText);
            var newValue = 0;

            switch (ex.GetMemberName())
            {
                case "Add": newValue = x + y; break;
                case "Sub": newValue = x - y; break;
                case "Mul": newValue = x * y; break;
                case "Div": newValue = x / y; break;
            }

            var newLiteral = SyntaxFactory.LiteralExpression(SyntaxKind.NumericLiteralExpression, SyntaxFactory.Literal(newValue))
                .WithLeadingTrivia(ex.GetLeadingTrivia())
                .WithTrailingTrivia(ex.GetTrailingTrivia())
                ;

            var oldRoot = await document.GetSyntaxRootAsync(cancellationToken);
            var newRoot = oldRoot.ReplaceNode(ex, newLiteral);

            return document.WithSyntaxRoot(newRoot);
        }
开发者ID:ufcpp,项目名称:UfcppSample,代码行数:30,代码来源:LiteralFix.cs


示例18: VisitInvocationExpression

 public override SyntaxNode VisitInvocationExpression(InvocationExpressionSyntax node)
 {
     var memberAccessExpression = node.Expression as MemberAccessExpressionSyntax;
     if (memberAccessExpression != null && memberAccessExpression.Name.ToString() == "TransformExpression")
         _transform = true;
     return base.VisitInvocationExpression(node);
 }
开发者ID:bnjMichel,项目名称:waqs,代码行数:7,代码来源:ExpressionTransformerRewriter.cs


示例19: IsLambdaWithoutBody

 private static bool IsLambdaWithoutBody(InvocationExpressionSyntax invocation)
 {
     var arg = invocation.ArgumentList?.Arguments.First();
     var lambda = arg.Expression as LambdaExpressionSyntax;
     if (lambda == null) return false;
     return !(lambda.Body is BlockSyntax);
 }
开发者ID:Vossekop,项目名称:code-cracker,代码行数:7,代码来源:ChangeAnyToAllAnalyzer.cs


示例20: VisitInvocationExpression

        public override void VisitInvocationExpression(InvocationExpressionSyntax node)
        {
            var symbol = (IMethodSymbol)SemanticModel.GetSymbolInfo(node).Symbol;
            
            if (symbol != null)
            {
                var asynctype = DetectAsynchronousUsages(node, symbol);
                Result.StoreDetectedAsyncUsage(asynctype);
                Result.WriteDetectedAsyncUsage(asynctype, Document.FilePath, symbol);
                Result.WriteDetectedAsyncUsageToTable(asynctype,Document,symbol,node);
                //if (asynctype == Enums.AsyncDetected.Task || asynctype == Enums.AsyncDetected.Threadpool || asynctype == Enums.AsyncDetected.Thread)
                //{
                //    foreach (var methodCall in node.DescendantNodes().OfType<InvocationExpressionSyntax>())
                //    {

                //        var methodCallSymbol = (MethodSymbol)SemanticModel.GetSymbolInfo(methodCall).Symbol;

                //        if (methodCallSymbol != null)
                //        {
                //            var synctype = ((MethodSymbol)methodCallSymbol.OriginalDefinition).DetectSynchronousUsages(SemanticModel);

                //            if (synctype != Utilities.Enums.SyncDetected.None)
                //                Logs.TempLog.Info("LONGRUNNING {0} {1}\r\n{2}\r\n--------------------------", methodCallSymbol, Document.FilePath, node);
                //        }
                //    }
                //}
                 
            }


            base.VisitInvocationExpression(node);
        }
开发者ID:modulexcite,项目名称:CSharpAnalyzer,代码行数:32,代码来源:AsyncUsageDetectionWalker.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Invoice类代码示例发布时间:2022-05-24
下一篇:
C# InvocationExpression类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap