当前位置: 首页>>代码示例>>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;未经允许,请勿转载。