本文整理匯總了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));
}