當前位置: 首頁>>代碼示例>>C#>>正文


C# AssignmentExpressionSyntax.GetLocation方法代碼示例

本文整理匯總了C#中AssignmentExpressionSyntax.GetLocation方法的典型用法代碼示例。如果您正苦於以下問題:C# AssignmentExpressionSyntax.GetLocation方法的具體用法?C# AssignmentExpressionSyntax.GetLocation怎麽用?C# AssignmentExpressionSyntax.GetLocation使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在AssignmentExpressionSyntax的用法示例。


在下文中一共展示了AssignmentExpressionSyntax.GetLocation方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: AnalyzeAssignment

        void AnalyzeAssignment(SyntaxNodeAnalysisContext context, AssignmentExpressionSyntax assignment)
        {
            var containingMethod = assignment.GetContainingMethod();
            if (containingMethod.HasConstAttribute(context.SemanticModel)) {
                if (context.SemanticModel.GetSymbolInfo(assignment.Left).Symbol?.Kind == SymbolKind.Local) {
                    return;
                }

                var left = assignment.Left as MemberAccessExpressionSyntax;
                if (left != null) {
                    var walker = new Walker(context);
                    containingMethod.Accept(walker);
                    var exprSymbol = context.SemanticModel.GetSymbolInfo(left.Expression).Symbol;
                    if (exprSymbol != null && exprSymbol.Kind == SymbolKind.Local && !walker.UnsafeLocals.Contains(exprSymbol.Name)) {
                        return;
                    }
                }
                context.ReportDiagnostic(Diagnostic.Create(Rule, assignment.GetLocation(), context.SemanticModel.GetDeclaredSymbol(containingMethod)?.Name));
            }
        }
開發者ID:FonsDijkstra,項目名稱:CConst,代碼行數:20,代碼來源:AssignmentInConstMethodAnalyzer.cs

示例2: AnalyzeAssignment

        void AnalyzeAssignment(SyntaxNodeAnalysisContext context, AssignmentExpressionSyntax assignment)
        {
            var constructor = assignment.GetContainingConstructor();
            if (constructor == null)
            {
                return;
            }

            var symbol = context.SemanticModel.GetSymbolInfo(assignment.Left).Symbol;
            if (symbol?.Kind == SymbolKind.Local)
            {
                return;
            }

            var constructorSymbol = context.SemanticModel.GetDeclaredSymbol(constructor);
            if (symbol?.ContainingType == constructorSymbol.ContainingType)
            {
                return;
            }

            context.ReportDiagnostic(Diagnostic.Create(Rule, assignment.GetLocation(), constructorSymbol.Name));
        }
開發者ID:FonsDijkstra,項目名稱:CConst,代碼行數:22,代碼來源:ConstConstructorAnalyzer.cs

示例3: FindAvailableStringBuilderVariableName

 private static string FindAvailableStringBuilderVariableName(AssignmentExpressionSyntax assignmentExpression, SemanticModel semanticModel)
 {
     const string builderNameBase = "builder";
     var builderName = builderNameBase;
     var builderNameIncrementer = 0;
     while (semanticModel.LookupSymbols(assignmentExpression.GetLocation().SourceSpan.Start, name: builderName).Any())
         builderName = builderNameBase + ++builderNameIncrementer;
     return builderName;
 }
開發者ID:haroldhues,項目名稱:code-cracker,代碼行數:9,代碼來源:StringBuilderInLoopCodeFixProvider.cs

示例4: VisitAssignmentExpression

            public override void VisitAssignmentExpression(AssignmentExpressionSyntax assignment)
            {
                var symbol = context.SemanticModel.GetSymbolInfo(assignment.Left).Symbol;
                if (symbol == null) {
                    return;
                }

                if (symbol.Kind == SymbolKind.Local ||
                    (symbol.Kind == SymbolKind.Parameter && ((IParameterSymbol)symbol).RefKind != RefKind.Ref)) {
                    return;
                }

                if ((symbol.Kind == SymbolKind.Field || symbol.Kind == SymbolKind.Property) &&
                    symbol.ContainedIn(constructorSymbol.ContainingType) &&
                    symbol.IsStatic == constructorSymbol.IsStatic) {
                    return;
                }

                context.ReportDiagnostic(Diagnostic.Create(Rule, assignment.GetLocation(), constructorSymbol.Name));
            }
開發者ID:FonsDijkstra,項目名稱:CConst,代碼行數:20,代碼來源:ConstConstructorAnalyzer.cs


注:本文中的AssignmentExpressionSyntax.GetLocation方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。