本文整理汇总了C#中AssignmentExpressionSyntax类的典型用法代码示例。如果您正苦于以下问题:C# AssignmentExpressionSyntax类的具体用法?C# AssignmentExpressionSyntax怎么用?C# AssignmentExpressionSyntax使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AssignmentExpressionSyntax类属于命名空间,在下文中一共展示了AssignmentExpressionSyntax类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VisitAssignmentExpression
/// <summary>
/// Normalizes the <paramref name="assignment" />.
/// </summary>
public override SyntaxNode VisitAssignmentExpression(AssignmentExpressionSyntax assignment)
{
if (!IsFormulaType(assignment.Left) || IsFormulaType(assignment.Right))
return base.VisitAssignmentExpression(assignment);
return assignment.WithRight(CreateInvocation(assignment.Right));
}
示例2: AnalyzeOwnershipInAssignment
/// <summary>
/// Analyzes the ownership of the given-up symbol
/// in the assignment expression.
/// </summary>
/// <param name="givenUpSymbol">GivenUpOwnershipSymbol</param>
/// <param name="assignment">AssignmentExpressionSyntax</param>
/// <param name="statement">Statement</param>
/// <param name="machine">StateMachine</param>
/// <param name="model">SemanticModel</param>
/// <param name="trace">TraceInfo</param>
protected override void AnalyzeOwnershipInAssignment(GivenUpOwnershipSymbol givenUpSymbol,
AssignmentExpressionSyntax assignment, Statement statement, StateMachine machine,
SemanticModel model, TraceInfo trace)
{
var leftIdentifier = base.AnalysisContext.GetRootIdentifier(assignment.Left);
ISymbol leftSymbol = model.GetSymbolInfo(leftIdentifier).Symbol;
if (assignment.Right is IdentifierNameSyntax)
{
var rightIdentifier = base.AnalysisContext.GetRootIdentifier(assignment.Right);
ISymbol rightSymbol = model.GetSymbolInfo(rightIdentifier).Symbol;
if (statement.Summary.DataFlowAnalysis.FlowsIntoSymbol(rightSymbol,
givenUpSymbol.ContainingSymbol, statement, givenUpSymbol.Statement))
{
var type = model.GetTypeInfo(assignment.Right).Type;
if (leftSymbol != null && leftSymbol.Kind == SymbolKind.Field &&
base.IsFieldAccessedInSuccessor(leftSymbol as IFieldSymbol, statement.Summary, machine) &&
!base.AnalysisContext.IsTypePassedByValueOrImmutable(type))
{
TraceInfo newTrace = new TraceInfo();
newTrace.Merge(trace);
newTrace.AddErrorTrace(statement.SyntaxNode);
AnalysisErrorReporter.ReportGivenUpOwnershipFieldAssignment(newTrace, leftSymbol);
}
return;
}
}
else if (assignment.Right is MemberAccessExpressionSyntax)
{
this.AnalyzeOwnershipInExpression(givenUpSymbol, assignment.Right, statement,
machine, model, trace);
}
else if (assignment.Right is InvocationExpressionSyntax ||
assignment.Right is ObjectCreationExpressionSyntax)
{
trace.InsertCall(statement.Summary.Method, assignment.Right);
base.AnalyzeOwnershipInCall(givenUpSymbol, assignment.Right, statement,
machine, model, trace);
}
if (assignment.Left is MemberAccessExpressionSyntax)
{
ISymbol outerLeftMemberSymbol = model.GetSymbolInfo(assignment.Left).Symbol;
if (!outerLeftMemberSymbol.Equals(leftSymbol) &&
statement.Summary.DataFlowAnalysis.FlowsIntoSymbol(givenUpSymbol.ContainingSymbol,
leftSymbol, givenUpSymbol.Statement, statement))
{
TraceInfo newTrace = new TraceInfo();
newTrace.Merge(trace);
newTrace.AddErrorTrace(statement.SyntaxNode);
AnalysisErrorReporter.ReportGivenUpOwnershipAccess(newTrace);
}
}
}
示例3: BindDeconstructionAssignment
private BoundExpression BindDeconstructionAssignment(AssignmentExpressionSyntax node, DiagnosticBag diagnostics)
{
var left = (TupleExpressionSyntax)node.Left;
ArrayBuilder<DeconstructionVariable> checkedVariables = BindDeconstructionAssignmentVariables(left.Arguments, left, diagnostics);
var result = BindDeconstructionAssignment(node, node.Right, checkedVariables, diagnostics, isDeclaration: false);
FreeDeconstructionVariables(checkedVariables);
return result;
}
示例4: ParseIfStatement
internal static bool ParseIfStatement(IfStatementSyntax node, out ExpressionSyntax condition, out ExpressionSyntax target, out AssignmentExpressionSyntax whenTrue, out AssignmentExpressionSyntax whenFalse)
{
condition = null;
target = null;
whenTrue = null;
whenFalse = null;
if (node == null || node.Else == null || node.Parent is IfStatementSyntax || node.Else.Statement is IfStatementSyntax)
return false;
condition = node.Condition;
//make sure to check for multiple statements
ExpressionStatementSyntax whenTrueExprStatement, whenFalseExprStatement;
var embeddedBlock = node.Statement as BlockSyntax;
if (embeddedBlock != null)
{
if (embeddedBlock.Statements.Count > 1)
return false;
var childNodes = embeddedBlock.ChildNodes();
if (childNodes.Count() > 1)
return false;
whenTrueExprStatement = childNodes.OfType<ExpressionStatementSyntax>().FirstOrDefault();
}
else
{
whenTrueExprStatement = node.Statement as ExpressionStatementSyntax;
}
var elseBlock = node.Else.Statement as BlockSyntax;
if (elseBlock != null)
{
if (elseBlock.Statements.Count > 1)
return false;
var childNodes = elseBlock.ChildNodes();
if (childNodes.Count() > 1)
return false;
whenFalseExprStatement = childNodes.OfType<ExpressionStatementSyntax>().FirstOrDefault();
}
else
{
whenFalseExprStatement = node.Else.Statement as ExpressionStatementSyntax;
}
if (whenTrueExprStatement == null || whenFalseExprStatement == null)
return false;
whenTrue = whenTrueExprStatement.Expression as AssignmentExpressionSyntax;
whenFalse = whenFalseExprStatement.Expression as AssignmentExpressionSyntax;
if (whenTrue == null || whenFalse == null || whenTrue.Kind() != whenFalse.Kind() ||
!SyntaxFactory.AreEquivalent(whenTrue.Left, whenFalse.Left))
return false;
return true;
}
开发者ID:alecor191,项目名称:RefactoringEssentials,代码行数:54,代码来源:ConvertIfStatementToConditionalTernaryExpressionCodeRefactoringProvider.cs
示例5: VisitAssignmentExpression
public override void VisitAssignmentExpression(AssignmentExpressionSyntax node)
{
cb.AppendIndent();
Visit(node.Left);
cb.Append(" = ");
Visit(node.Right);
cb.AppendLine(";");
}
示例6: AnalyzeOwnershipInAssignment
/// <summary>
/// Analyzes the ownership of the given-up symbol
/// in the assignment expression.
/// </summary>
/// <param name="givenUpSymbol">GivenUpOwnershipSymbol</param>
/// <param name="assignment">AssignmentExpressionSyntax</param>
/// <param name="statement">Statement</param>
/// <param name="machine">StateMachine</param>
/// <param name="model">SemanticModel</param>
/// <param name="trace">TraceInfo</param>
protected override void AnalyzeOwnershipInAssignment(GivenUpOwnershipSymbol givenUpSymbol,
AssignmentExpressionSyntax assignment, Statement statement, StateMachine machine,
SemanticModel model, TraceInfo trace)
{
IdentifierNameSyntax leftIdentifier = base.AnalysisContext.GetRootIdentifier(assignment.Left);
ISymbol leftSymbol = model.GetSymbolInfo(leftIdentifier).Symbol;
this.AnalyzeGivingUpFieldOwnership(givenUpSymbol, leftSymbol, statement, machine, trace);
this.AnalyzeOwnershipInExpression(givenUpSymbol, assignment.Right,
statement, machine, model, trace);
}
示例7: ReplaceAddExpressionByStringBuilderAppendExpression
private static SyntaxNode ReplaceAddExpressionByStringBuilderAppendExpression(AssignmentExpressionSyntax assignmentExpression, SyntaxNode expressionStatement, SyntaxNode expressionStatementParent, string builderName)
{
var appendExpressionOnLoop = assignmentExpression.IsKind(SyntaxKind.SimpleAssignmentExpression)
? SyntaxFactory.ParseStatement($"{builderName}.Append({((BinaryExpressionSyntax)assignmentExpression.Right).Right.ToString()});\r\n")
: SyntaxFactory.ParseStatement($"{builderName}.Append({assignmentExpression.Right.ToString()});\r\n");
appendExpressionOnLoop = appendExpressionOnLoop
.WithLeadingTrivia(expressionStatement.GetLeadingTrivia())
.WithTrailingTrivia(expressionStatement.GetTrailingTrivia());
var newExpressionStatementParent = expressionStatementParent.ReplaceNode(expressionStatement, appendExpressionOnLoop);
return newExpressionStatementParent;
}
示例8: IsAssignmentOutsideConstructor
private static bool IsAssignmentOutsideConstructor(AssignmentExpressionSyntax assignment, ISymbol fieldSymbol, SemanticModel model)
{
var assignedSymbol = model.GetSymbolInfo(assignment.Left);
if (assignedSymbol.Symbol != fieldSymbol)
{
return false;
}
// Method (or whatever) enclosing the assignment
var enclosingSymbol = model.GetEnclosingSymbol(assignment.SpanStart) as IMethodSymbol;
var isCtor = enclosingSymbol?.MethodKind == MethodKind.Constructor;
return !isCtor;
}
示例9: CheckConditionAndAssignment
static bool CheckConditionAndAssignment(SyntaxNodeAnalysisContext nodeContext, AssignmentExpressionSyntax assignment, BinaryExpressionSyntax condition)
{
if (assignment == null)
return false;
var assignmentTarget = nodeContext.SemanticModel.GetSymbolInfo(assignment.Left).Symbol;
if (assignmentTarget == null)
return false;
var condLeftSymbol = nodeContext.SemanticModel.GetSymbolInfo(condition.Left).Symbol;
var condRightSymbol = nodeContext.SemanticModel.GetSymbolInfo(condition.Right).Symbol;
var assignmentValue = nodeContext.SemanticModel.GetSymbolInfo(assignment.Right).Symbol;
var constant = nodeContext.SemanticModel.GetConstantValue(assignment.Right);
bool constantAssignment = assignmentValue == null && constant.HasValue;
if (assignmentTarget.Equals(condLeftSymbol))
{
if (constantAssignment)
{
var condRightValue = nodeContext.SemanticModel.GetConstantValue(condition.Right);
if (condRightValue.HasValue)
return condRightValue.Value == constant.Value;
}
else
{
if ((assignmentValue == null) || !assignmentValue.Equals(condRightSymbol))
return false;
}
return true;
}
// flipped operands
if (assignmentTarget.Equals(condRightSymbol))
{
if (constantAssignment)
{
var condLeftValue = nodeContext.SemanticModel.GetConstantValue(condition.Left);
if (condLeftValue.HasValue)
return condLeftValue.Value == constant.Value;
}
else
{
if ((assignmentValue == null) || !assignmentValue.Equals(condLeftSymbol))
return false;
}
return true;
}
return false;
}
示例10: VisitAssignmentExpression
/// <summary>
/// Normalizes the <paramref name="assignment" />.
/// </summary>
public override SyntaxNode VisitAssignmentExpression(AssignmentExpressionSyntax assignment)
{
var objectCreation = assignment.Right as ObjectCreationExpressionSyntax;
if (objectCreation == null)
return assignment;
var fault = SemanticModel.GetTypeSymbol<Fault>();
if (SemanticModel.GetTypeInfo(objectCreation).Type?.IsDerivedFrom(fault) == false)
return assignment;
var targetSymbol = SemanticModel.GetSymbolInfo(assignment.Left).Symbol;
if (targetSymbol == null || (targetSymbol.Kind != SymbolKind.Field && targetSymbol.Kind != SymbolKind.Property))
return assignment;
return assignment.WithRight(AddNameInitializer(fault, objectCreation, targetSymbol.Name));
}
示例11: GetMemberAccessExpressionFromAssignment
private static MemberAccessExpressionSyntax GetMemberAccessExpressionFromAssignment(SemanticModel semanticModel, AssignmentExpressionSyntax assignmentExpression, AssignmentExpressionSyntax nullLiteralAssignment)
{
if (assignmentExpression == null || nullLiteralAssignment == null
|| !assignmentExpression.IsKind(SyntaxKind.SimpleAssignmentExpression)
|| !assignmentExpression.IsKind(SyntaxKind.SimpleAssignmentExpression))
return null;
if (!nullLiteralAssignment.Right.IsKind(SyntaxKind.NullLiteralExpression)) return null;
if (!nullLiteralAssignment.Left.IsKind(SyntaxKind.IdentifierName)) return null;
if (!assignmentExpression.Left.IsKind(SyntaxKind.IdentifierName)) return null;
var assignmentIdentifier = semanticModel.GetSymbolInfo(assignmentExpression.Left);
var nullLiteralAssignmentIdentifier = semanticModel.GetSymbolInfo(nullLiteralAssignment.Left);
if ((assignmentIdentifier.Symbol ?? nullLiteralAssignmentIdentifier.Symbol) == null) return null;
if (!assignmentIdentifier.Equals(nullLiteralAssignmentIdentifier)) return null;
var memberAccessExpression = assignmentExpression.Right as MemberAccessExpressionSyntax;
return memberAccessExpression;
}
示例12: AddVariableThatWasSkippedBeforeBecauseItLackedAInitializer
private static void AddVariableThatWasSkippedBeforeBecauseItLackedAInitializer(Dictionary<IFieldSymbol, VariableDeclaratorSyntax> variablesToMakeReadonly, IFieldSymbol fieldSymbol, AssignmentExpressionSyntax assignment)
{
var parent = assignment.Parent;
while (parent != null)
{
if (parent is AnonymousFunctionExpressionSyntax)
return;
if (parent is ConstructorDeclarationSyntax)
break;
parent = parent.Parent;
}
if (!fieldSymbol.IsReadOnly && !variablesToMakeReadonly.Keys.Contains(fieldSymbol))
foreach (var variable in fieldSymbol.DeclaringSyntaxReferences)
variablesToMakeReadonly.Add(fieldSymbol, (VariableDeclaratorSyntax)variable.GetSyntax());
}
示例13: VisitAssignmentExpression
/// <summary>
/// Normalizes the <paramref name="expression" /> if it represents a compound assignment.
/// </summary>
public override SyntaxNode VisitAssignmentExpression(AssignmentExpressionSyntax expression)
{
expression = (AssignmentExpressionSyntax)base.VisitAssignmentExpression(expression);
SyntaxKind expressionKind;
switch (expression.Kind())
{
case SyntaxKind.AddAssignmentExpression:
expressionKind = SyntaxKind.AddExpression;
break;
case SyntaxKind.SubtractAssignmentExpression:
expressionKind = SyntaxKind.SubtractExpression;
break;
case SyntaxKind.MultiplyAssignmentExpression:
expressionKind = SyntaxKind.MultiplyExpression;
break;
case SyntaxKind.DivideAssignmentExpression:
expressionKind = SyntaxKind.DivideExpression;
break;
case SyntaxKind.ModuloAssignmentExpression:
expressionKind = SyntaxKind.ModuloExpression;
break;
case SyntaxKind.AndAssignmentExpression:
expressionKind = SyntaxKind.LogicalAndExpression;
break;
case SyntaxKind.ExclusiveOrAssignmentExpression:
expressionKind = SyntaxKind.ExclusiveOrExpression;
break;
case SyntaxKind.OrAssignmentExpression:
expressionKind = SyntaxKind.LogicalOrExpression;
break;
case SyntaxKind.LeftShiftAssignmentExpression:
expressionKind = SyntaxKind.LeftShiftExpression;
break;
case SyntaxKind.RightShiftAssignmentExpression:
expressionKind = SyntaxKind.RightShiftExpression;
break;
default:
return expression;
}
var originalRightHand = (ExpressionSyntax)Visit(expression.Right);
var parenthesizedExpression = SyntaxFactory.ParenthesizedExpression(originalRightHand).WithLeadingSpace();
var rightHandExpression = SyntaxFactory.BinaryExpression(expressionKind, expression.Left.WithLeadingSpace(), parenthesizedExpression);
var simpleAssignment = SyntaxFactory.AssignmentExpression(SyntaxKind.SimpleAssignmentExpression, expression.Left, rightHandExpression);
return simpleAssignment.WithTrivia(expression);
}
示例14: CreateAssignment
internal static AssignmentExpressionSyntax CreateAssignment(AssignmentExpressionSyntax node)
{
var bop = node.Right as BinaryExpressionSyntax;
if (bop == null)
return null;
var outerLeft = GetOuterLeft(bop);
var outerLeftId = outerLeft as IdentifierNameSyntax;
var leftId = node.Left as IdentifierNameSyntax;
if (outerLeftId == null || leftId == null)
return null;
if (!outerLeftId.Identifier.Value.Equals (leftId.Identifier.Value))
return null;
var op = GetAssignmentOperator(bop.OperatorToken);
if (op == SyntaxKind.None)
return null;
return SyntaxFactory.AssignmentExpression(op, node.Left, SplitIfWithAndConditionInTwoCodeRefactoringProvider.GetRightSide(outerLeft.Parent as BinaryExpressionSyntax));
}
开发者ID:alecor191,项目名称:RefactoringEssentials,代码行数:17,代码来源:ReplaceWithOperatorAssignmentCodeRefactoringProvider.cs
示例15: VisitAssignmentExpression
/// <summary>
/// Normalizes the <paramref name="expression" />.
/// </summary>
public override SyntaxNode VisitAssignmentExpression(AssignmentExpressionSyntax expression)
{
if (!_inConstructor)
return expression;
var propertySymbol = SemanticModel.GetSymbolInfo(expression.Left).Symbol as IPropertySymbol;
expression = (AssignmentExpressionSyntax)base.VisitAssignmentExpression(expression);
if (propertySymbol == null || !propertySymbol.IsAutoProperty())
return expression;
if (propertySymbol.GetMethod != null && !propertySymbol.GetMethod.CanBeAffectedByFaults(SemanticModel))
return expression;
var fieldExpression = (ExpressionSyntax)Syntax.IdentifierName(GetBackingFieldName(propertySymbol)).WithTrivia(expression.Left);
return expression.WithLeft(fieldExpression);
}