本文整理汇总了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));
}
}
示例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));
}
示例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;
}
示例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));
}