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


C# InvocationExpressionSyntax.GetLocation方法代码示例

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


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

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

示例2: CheckForCondition

 private static void CheckForCondition(SyntaxNodeAnalysisContext context, InvocationExpressionSyntax invocationNode, 
   SyntaxNode expressionStatementParent, DiagnosticDescriptor descriptor)
 {
   if ((!expressionStatementParent?.DescendantNodesAndTokens()?.Any(_ => _.IsKind(SyntaxKind.EqualsToken)) ?? false) &&
     !(invocationNode.DescendantNodes()?.Any(_ => new ContainsInvocationExpressionWalker(_).HasIssue) ?? false))
   {
     context.ReportDiagnostic(Diagnostic.Create(descriptor, invocationNode.GetLocation()));
   }
 }
开发者ID:StrickDev,项目名称:csla,代码行数:9,代码来源:FindSaveAssignmentIssueAnalyzer.cs

示例3: CheckForCondition

 private static void CheckForCondition(SyntaxNodeAnalysisContext context, InvocationExpressionSyntax invocationNode, 
   SyntaxNode expressionStatementParent, DiagnosticDescriptor descriptor)
 {
   // Make sure the invocation's containing type is not the same as the class that contains it
   if ((invocationNode.DescendantNodesAndTokens().Any(_ => _.IsKind(SyntaxKind.DotToken)) &&
     !invocationNode.DescendantNodesAndTokens().Any(_ => _.IsKind(SyntaxKind.ThisExpression) || _.IsKind(SyntaxKind.BaseExpression))) &&
     (!expressionStatementParent?.DescendantNodesAndTokens()?.Any(_ => _.IsKind(SyntaxKind.EqualsToken)) ?? false) &&
     !(invocationNode.DescendantNodes()?.Any(_ => new ContainsInvocationExpressionWalker(_).HasIssue) ?? false) &&
     !FindSaveAssignmentIssueAnalyzer.IsReturnValue(invocationNode))
   {
     context.ReportDiagnostic(Diagnostic.Create(descriptor, invocationNode.GetLocation()));
   }
 }
开发者ID:RodrigoGT,项目名称:csla,代码行数:13,代码来源:FindSaveAssignmentIssueAnalyzer.cs

示例4: AnalyzeInvocation

        static void AnalyzeInvocation(SyntaxNodeAnalysisContext context, IMethodSymbol symbol,
            InvocationExpressionSyntax invocation, INamedTypeSymbol nunitAssert)
        {
            if (symbol?.MethodKind != MethodKind.Ordinary
                || !symbol.IsStatic
                || !NUnitAssertMethods.Type.Equals(symbol.ContainingType)) return;

            if (!symbol.ContainingType.Equals(nunitAssert)) return;

            if (!IsAnAssert(symbol)) return;

            var diagnostic = Diagnostic.Create(descriptor, invocation.GetLocation(), symbol.Name);
            context.ReportDiagnostic(diagnostic);
        }
开发者ID:vbfox,项目名称:NFluentConversion,代码行数:14,代码来源:ReplaceNUnitAnalyzer.cs

示例5: AnalyzeInvocation

 void AnalyzeInvocation(SyntaxNodeAnalysisContext context, InvocationExpressionSyntax invocation)
 {
     var containingMethod = invocation.GetContainingMethod();
     if (containingMethod.HasConstAttribute(context.SemanticModel))
     {
         var invokedMethod = invocation.GetInvokedMethod(context.SemanticModel);
         if (!invokedMethod.Syntax.HasConstAttribute(invokedMethod.Model))
         {
             context.ReportDiagnostic(Diagnostic.Create(Rule,
                 invocation.GetLocation(),
                 context.SemanticModel.GetDeclaredSymbol(containingMethod)?.Name,
                 context.SemanticModel.GetSymbolInfo(invocation).Symbol?.Name));
         }
     }
 }
开发者ID:FonsDijkstra,项目名称:CConst,代码行数:15,代码来源:InvocationInConstMethodAnalyzer.cs

示例6: CheckParam

 private static void CheckParam(InvocationExpressionSyntax invocationExpression, IMethodSymbol methodInfo, SemanticModel semanticModel, Action<Diagnostic> reportDiagnostic, string filePath, CancellationToken cancellationToken)
 {
     var arguments = invocationExpression.ArgumentList.Arguments;
     if (arguments.Count != methodInfo.Parameters.Length)
     {
         reportDiagnostic(Diagnostic.Create(ParamsParameterRule, invocationExpression.GetLocation(), EmptyMessageArgs));
         HeapAllocationAnalyzerEventSource.Logger.ParamsAllocation(filePath);
     }
     else
     {
         var lastIndex = arguments.Count - 1;
         var lastArgumentTypeInfo = semanticModel.GetTypeInfo(arguments[lastIndex].Expression, cancellationToken);
         if (lastArgumentTypeInfo.Type != null && !lastArgumentTypeInfo.Type.Equals(methodInfo.Parameters[lastIndex].Type))
         {
             reportDiagnostic(Diagnostic.Create(ParamsParameterRule, invocationExpression.GetLocation(), EmptyMessageArgs));
             HeapAllocationAnalyzerEventSource.Logger.ParamsAllocation(filePath);
         }
     }
 }
开发者ID:Maxwe11,项目名称:RoslynClrHeapAllocationAnalyzer,代码行数:19,代码来源:CallSiteImplicitAllocationAnalyzer.cs

示例7: ValidateMethodCallInLinqExpression

        internal static void ValidateMethodCallInLinqExpression(InvocationExpressionSyntax node, EFCodeFirstClassInfo rootQueryableType, SyntaxNodeAnalysisContext context, EFUsageContext efContext, Dictionary<string, ContextualLinqParameter> parameterNodes, bool treatAsWarning)
        {
            string methodName = null;
            var memberExpr = node.Expression as MemberAccessExpressionSyntax;
            var identExpr = node.Expression as IdentifierNameSyntax;
            if (memberExpr != null)
            {
                methodName = memberExpr?.Name?.Identifier.ValueText;

                //This is a LINQ operator (Where, Select, etc)
                if (CanonicalMethodNames.IsLinqOperator(methodName))
                {
                    var expr = memberExpr.Expression as MemberAccessExpressionSyntax;
                    if (expr != null) //a.b.<linq operator>()
                    {
                        //What is b?
                        var member = expr.Name as IdentifierNameSyntax;
                        if (member != null)
                        {
                            string memberName = member.Identifier.ValueText;
                            var applicableClasses = efContext.GetClassForProperty(memberName)
                                                             .Where(c => c.HasProperty(memberName));
                            
                            if (applicableClasses.Count() > 1)
                            {
                                //See if semantic model can help us disambiguate
                                var si = context.SemanticModel.GetSymbolInfo(expr.Expression);
                                var type = si.Symbol?.TryGetType();
                                if (type != null)
                                {
                                    var cls = efContext.GetClassInfo(type);
                                    //There is only one class with this property and it is confirmed to be a collection
                                    //navigation property
                                    if (cls != null && cls.IsCollectionNavigationProperty(memberName))
                                    {
                                        ValidateNavigationPropertyAccess(node, context, efContext, treatAsWarning, memberName, cls);
                                    }
                                }
                                else
                                {
                                    //This potential navigation property resolves to multiple classes, see if we can resolve to a
                                    //single one via contextual variables
                                    var inst = expr.Expression as IdentifierNameSyntax;
                                    if (inst != null)
                                    {
                                        string name = inst.Identifier.ValueText;
                                        ContextualLinqParameter cparam;
                                        if (parameterNodes.TryGetValue(name, out cparam) && 
                                            cparam.ParameterType == ContextualLinqParameterType.Queryable &&
                                            applicableClasses.Any(c => c.ClassType == cparam.QueryableType.ClassType))
                                        {
                                            //TODO: Code fix candidate
                                            //
                                            //In such a case, inject an .AsQueryable() before the LINQ operator call
                                            //and add using System.Linq if required
                                            var diagnostic = Diagnostic.Create(treatAsWarning ? DiagnosticCodes.EFLINQ009 : DiagnosticCodes.EFLINQ008, member.GetLocation(), memberName, cparam.QueryableType.Name);
                                            context.ReportDiagnostic(diagnostic);
                                        }
                                        else
                                        {
                                            //TODO: Code fix candidate
                                            //
                                            //In such a case, inject an .AsQueryable() before the LINQ operator call
                                            //and add using System.Linq if required
                                            var diagnostic = Diagnostic.Create(DiagnosticCodes.EFLINQ010, member.GetLocation(), memberName);
                                            context.ReportDiagnostic(diagnostic);
                                        }
                                    }
                                    else
                                    {
                                        //TODO: Code fix candidate
                                        //
                                        //In such a case, inject an .AsQueryable() before the LINQ operator call
                                        //and add using System.Linq if required
                                        var diagnostic = Diagnostic.Create(DiagnosticCodes.EFLINQ010, member.GetLocation(), memberName);
                                        context.ReportDiagnostic(diagnostic);
                                    }
                                }
                            }
                            else
                            {
                                var cls = applicableClasses.FirstOrDefault();
                                //There is only one class with this property and it is confirmed to be a collection
                                //navigation property
                                if (cls != null && cls.IsCollectionNavigationProperty(memberName))
                                {
                                    ValidateNavigationPropertyAccess(node, context, efContext, treatAsWarning, memberName, cls);
                                }
                            }
                        }
                        //TODO: If not, check that the preceding member is IQueryable<T> and that T is a known
                        //entity type
                    }
                }
                else
                {
                    //TODO: AsQueryable() shouldn't be a blanket exception.
                    //We obviously should check what precedes it
                    if (methodName != EFSpecialIdentifiers.AsQueryable)
                    {
//.........这里部分代码省略.........
开发者ID:jumpinjackie,项目名称:roslyn-ef-linq-analyzer,代码行数:101,代码来源:LinqExpressionValidator.cs

示例8: GetInvocationTargetType

		private ITypeSymbol GetInvocationTargetType(int pos, InvocationExpressionSyntax node, IMethodSymbol methodSymbol)
		{
			ITypeSymbol retval;
			var notError = false;

			if (node.Expression is MemberAccessExpressionSyntax)
			{
				retval = this.semanticModel.GetSpeculativeTypeInfo(pos, ((MemberAccessExpressionSyntax)node.Expression).Expression, SpeculativeBindingOption.BindAsExpression).Type;
			}
			else if (node.Expression is IdentifierNameSyntax)
			{
				notError = true;
				retval = null;
			}
			else if (node.Expression is MemberBindingExpressionSyntax)
			{
				if (node.Parent is ConditionalAccessExpressionSyntax)
				{
					retval = this.semanticModel.GetSpeculativeTypeInfo(pos, ((ConditionalAccessExpressionSyntax)node.Parent).Expression, SpeculativeBindingOption.BindAsExpression).Type;
				}
				else if (node.Parent is MemberAccessExpressionSyntax)
				{
					retval = this.semanticModel.GetSpeculativeTypeInfo(pos, ((MemberAccessExpressionSyntax)node.Parent).Expression, SpeculativeBindingOption.BindAsExpression).Type;
				}
				else
				{
					var property = node.Parent?.GetType().GetProperty("Expression");

					if (property != null)
					{
						retval =
							this.semanticModel.GetSpeculativeTypeInfo
								(pos, (SyntaxNode)property.GetValue(node.Parent), SpeculativeBindingOption.BindAsExpression).Type;
					}
					else
					{
						retval = null;
					}
				}
			}
			else
			{
				retval = null;
			}

			if (retval == null)
			{
				retval = methodSymbol.ExtensionMethodNormalizingReceiverType();

				if (!notError)
				{
					this.log.LogError($"Unable to determine type of {node.Expression} in {node.SyntaxTree.FilePath} {node.Expression.GetType()} at {node.GetLocation().GetMappedLineSpan()}");
				}
			}

			return retval;
		}
开发者ID:tumtumtum,项目名称:Shaolinq,代码行数:57,代码来源:MethodInvocationInspector.cs

示例9: WriteDetectedAsyncUsageToTable

        internal void WriteDetectedAsyncUsageToTable(Enums.AsyncDetected type, Microsoft.CodeAnalysis.Document Document, IMethodSymbol symbol, InvocationExpressionSyntax node)
        {
            if (Enums.AsyncDetected.None != type)
            {
                string resultfile = @"C:\Users\Semih\Desktop\Tables\" + (int)type + ".txt";
                string delimStr = "/";
                char[] delimiter = delimStr.ToCharArray();
                var location = node.GetLocation().GetLineSpan();
                var app= AppName.Replace("+","/");

                string filepathWithLineNumbers = "http://www.github.com/"+ app +"/blob/" + commit +"/"+
                    Document.FilePath.Replace(@"\",@"/").Split(delimiter,6)[5] +"#L"+(location.StartLinePosition.Line+1)+"-"+(location.EndLinePosition.Line+1);
                var row = String.Format(@"<tr> <td>{0}</td><td>{1}</td><td><a href='{2}'>Link to Source Code</a></td> </tr>", app, symbol, filepathWithLineNumbers);

                using (StreamWriter sw = File.AppendText(resultfile))
                {
                    sw.WriteLine(row);
                }	

            }
        }
开发者ID:modulexcite,项目名称:CSharpAnalyzer,代码行数:21,代码来源:AsyncAnalysisResult.cs

示例10: CheckForIsAssignableFrom

        private static void CheckForIsAssignableFrom(SyntaxNodeAnalysisContext context, InvocationExpressionSyntax invocation,
            MemberAccessExpressionSyntax memberAccess, IMethodSymbol methodSymbol,
            ExpressionSyntax argument)
        {
            if (methodSymbol.Name != "IsAssignableFrom" ||
                !TypeExaminationOnSystemType.IsGetTypeCall(argument as InvocationExpressionSyntax, context.SemanticModel))
            {
                return;
            }

            if (memberAccess.Expression is TypeOfExpressionSyntax)
            {
                context.ReportDiagnostic(Diagnostic.Create(Rule, invocation.GetLocation(),
                    ImmutableDictionary<string, string>.Empty
                        .Add(UseIsOperatorKey, true.ToString())
                        .Add(ShouldRemoveGetType, true.ToString()),
                    IsOperator));
            }
            else
            {
                context.ReportDiagnostic(Diagnostic.Create(Rule, invocation.GetLocation(),
                    ImmutableDictionary<string, string>.Empty
                        .Add(UseIsOperatorKey, false.ToString())
                        .Add(ShouldRemoveGetType, true.ToString()),
                    IsInstanceOfType));
            }
        }
开发者ID:dbolkensteyn,项目名称:sonarlint-vs,代码行数:27,代码来源:GetTypeWithIsAssignableFrom.cs

示例11: CheckForIsInstanceOfType

        private static void CheckForIsInstanceOfType(SyntaxNodeAnalysisContext context, InvocationExpressionSyntax invocation,
            MemberAccessExpressionSyntax memberAccess, IMethodSymbol methodSymbol)
        {
            if (methodSymbol.Name != "IsInstanceOfType")
            {
                return;
            }

            if (memberAccess.Expression is TypeOfExpressionSyntax)
            {
                context.ReportDiagnostic(Diagnostic.Create(Rule, invocation.GetLocation(),
                    ImmutableDictionary<string, string>.Empty
                        .Add(UseIsOperatorKey, true.ToString())
                        .Add(ShouldRemoveGetType, false.ToString()),
                    IsOperator));
            }
        }
开发者ID:dbolkensteyn,项目名称:sonarlint-vs,代码行数:17,代码来源:GetTypeWithIsAssignableFrom.cs


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