本文整理汇总了C#中AssignmentExpression类的典型用法代码示例。如果您正苦于以下问题:C# AssignmentExpression类的具体用法?C# AssignmentExpression怎么用?C# AssignmentExpression使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AssignmentExpression类属于命名空间,在下文中一共展示了AssignmentExpression类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetActions
public IEnumerable<CodeAction> GetActions(RefactoringContext context)
{
if (context.IsSomethingSelected) {
yield break;
}
AstType type;
var varDecl = GetVariableDeclarationStatement(context, out type);
if (varDecl == null) {
yield break;
}
yield return new CodeAction(context.TranslateString("Split local variable declaration and assignment"), script => {
var assign = new AssignmentExpression (new IdentifierExpression (varDecl.Variables.First().Name), AssignmentOperatorType.Assign, varDecl.Variables.First().Initializer.Clone());
var newVarDecl = (VariableDeclarationStatement)varDecl.Clone();
newVarDecl.Role = BlockStatement.StatementRole;
if (newVarDecl.Type.IsMatch(new SimpleType ("var"))) {
newVarDecl.Type = type;
}
newVarDecl.Variables.First().Initializer = Expression.Null;
script.InsertBefore(varDecl, newVarDecl);
script.Replace(varDecl, varDecl.Parent is ForStatement ? (AstNode)assign : new ExpressionStatement (assign));
}, varDecl.Variables.First ().AssignToken);
}
示例2: VisitAssignmentExpression
public override void VisitAssignmentExpression(AssignmentExpression expression)
{
base.VisitAssignmentExpression (expression);
Identifier identifier = expression.FindIdentifier();
if (identifier == null)
return;
switch (expression.Operator)
{
case AssignmentOperatorType.BitwiseOr:
case AssignmentOperatorType.BitwiseAnd:
case AssignmentOperatorType.ExclusiveOr:
case AssignmentOperatorType.Add:
case AssignmentOperatorType.Subtract:
case AssignmentOperatorType.Divide:
case AssignmentOperatorType.Modulus:
case AssignmentOperatorType.Multiply:
case AssignmentOperatorType.ShiftLeft:
case AssignmentOperatorType.ShiftRight:
case AssignmentOperatorType.Assign:
this.lineMap[this.id++] = expression.StartLocation.Line;
break;
}
}
示例3: GetActions
public override IEnumerable<CodeAction> GetActions(RefactoringContext context)
{
if (context.IsSomethingSelected) {
yield break;
}
AstType type;
var varInitializer = GetVariableDeclarationStatement(context, out type);
if (varInitializer == null)
yield break;
var statement = varInitializer.GetParent<Statement>();
var declaration = varInitializer.GetParent<VariableDeclarationStatement>();
if (declaration == null || (declaration.Modifiers & Modifiers.Const) != 0)
yield break;
var selectedNode = varInitializer.GetNodeAt(context.Location) ?? varInitializer;
yield return new CodeAction(context.TranslateString("Split local variable declaration and assignment"), script => {
var assign = new AssignmentExpression (new IdentifierExpression (varInitializer.Name), AssignmentOperatorType.Assign, varInitializer.Initializer.Clone());
if (declaration != null && declaration.Type.IsVar())
script.Replace(declaration.Type, type);
if (declaration.Parent is ForStatement) {
script.InsertBefore(statement, new VariableDeclarationStatement (type, varInitializer.Name));
script.Replace(declaration, assign);
} else {
script.Replace(varInitializer, new IdentifierExpression (varInitializer.Name));
script.InsertAfter(statement, new ExpressionStatement (assign));
}
}, selectedNode);
}
示例4: VisitAssignmentExpression
public override void VisitAssignmentExpression(AssignmentExpression expression)
{
base.VisitAssignmentExpression (expression);
Identifier identifier = expression.FindIdentifier();
if (identifier == null)
return;
switch (expression.Operator)
{
case AssignmentOperatorType.BitwiseOr:
case AssignmentOperatorType.BitwiseAnd:
case AssignmentOperatorType.ExclusiveOr:
case AssignmentOperatorType.Add:
case AssignmentOperatorType.Subtract:
case AssignmentOperatorType.Divide:
case AssignmentOperatorType.Modulus:
case AssignmentOperatorType.Multiply:
case AssignmentOperatorType.ShiftLeft:
case AssignmentOperatorType.ShiftRight:
{
BinaryOperatorType op = GetComplexAssignOperator (expression.Operator);
Expression right = new BinaryOperatorExpression (new IdentifierExpression (identifier.Name), op, expression.Right.Clone());
expression.Operator = AssignmentOperatorType.Assign;
expression.Right = GetAssignmentExpression (identifier, right);
break;
}
case AssignmentOperatorType.Assign:
expression.Right = GetAssignmentExpression (identifier, expression.Right);
break;
}
}
示例5: VisitAssignmentExpression
public virtual object VisitAssignmentExpression(AssignmentExpression assignmentExpression, object data) {
Debug.Assert((assignmentExpression != null));
Debug.Assert((assignmentExpression.Left != null));
Debug.Assert((assignmentExpression.Right != null));
assignmentExpression.Left.AcceptVisitor(this, data);
return assignmentExpression.Right.AcceptVisitor(this, data);
}
示例6: Visit
public override void Visit(AssignmentExpression expression)
{
outStream.Write(printFuncName + "(");
expression.Left.Accept(this);
switch (expression.AssignmentOperator)
{
case AssignmentOperator.Add: outStream.Write(" += "); break;
case AssignmentOperator.And: outStream.Write(" &= "); break;
case AssignmentOperator.Assign: outStream.Write(" = "); break;
case AssignmentOperator.Divide: outStream.Write(" /= "); break;
case AssignmentOperator.Modulo: outStream.Write(" %= "); break;
case AssignmentOperator.Multiply: outStream.Write(" *= "); break;
case AssignmentOperator.Or: outStream.Write(" |= "); break;
case AssignmentOperator.ShiftLeft: outStream.Write(" <<= "); break;
case AssignmentOperator.ShiftRight: outStream.Write(" >>= "); break;
case AssignmentOperator.Substract: outStream.Write(" -= "); break;
case AssignmentOperator.UnsignedRightShift: outStream.Write(" >>>= "); break;
case AssignmentOperator.XOr: outStream.Write(" ^= "); break;
}
expression.Right.Accept(this);
outStream.Write(", \"{0}\")", TempName);
//int currentTempCounter = tempCounter++;
//outStream.Write("{0}{1} = ", tempVarName, currentTempCounter);
//expression.Right.Accept(this);
//outStream.WriteLine(";");
//outStream.WriteLine("{0}{1};\nprint({0}{1});", tempVarName, currentTempCounter, tempVarName, currentTempCounter);
}
示例7: VisitAssignmentExpression
public override void VisitAssignmentExpression (AssignmentExpression assignmentExpression)
{
base.VisitAssignmentExpression (assignmentExpression);
if (assignmentExpression.Operator != AssignmentOperatorType.Assign)
return;
if (!(assignmentExpression.Left is IdentifierExpression) &&
!(assignmentExpression.Left is MemberReferenceExpression))
return;
var resolveResult = ctx.Resolve (assignmentExpression.Left);
var memberResolveResult = resolveResult as MemberResolveResult;
if (memberResolveResult != null) {
var memberResolveResult2 = ctx.Resolve (assignmentExpression.Right) as MemberResolveResult;
if (memberResolveResult2 == null || !AreEquivalent(memberResolveResult, memberResolveResult2))
return;
} else if (resolveResult is LocalResolveResult) {
if (!assignmentExpression.Left.Match (assignmentExpression.Right).Success)
return;
} else {
return;
}
AstNode node;
Action<Script> action;
if (assignmentExpression.Parent is ExpressionStatement) {
node = assignmentExpression.Parent;
action = script => script.Remove (assignmentExpression.Parent);
} else {
node = assignmentExpression;
action = script => script.Replace (assignmentExpression, assignmentExpression.Left.Clone ());
}
AddIssue (node, ctx.TranslateString ("CS1717:Assignment made to same variable"),
new [] { new CodeAction (ctx.TranslateString ("Remove assignment"), action) });
}
示例8: GetNewEqualityTestCode
private static string GetNewEqualityTestCode(AssignmentExpression assignmentExpression)
{
RelationalOperation relationalOperation = new RelationalOperation(assignmentExpression.LeftSide.Clone() as Expression,
RelationalOperator.Equality,
assignmentExpression.RightSide.Clone() as Expression);
string newEqualityTest = CodeRush.Language.GenerateElement(relationalOperation);
return newEqualityTest;
}
示例9: ArgumentsInfo
public ArgumentsInfo(IEmitter emitter, AssignmentExpression assignmentExpression, OperatorResolveResult operatorResolveResult, IMethod method)
{
this.Emitter = emitter;
this.Expression = assignmentExpression;
this.OperatorResolveResult = operatorResolveResult;
this.BuildOperatorArgumentsList(new Expression[] { assignmentExpression.Left, assignmentExpression.Right }, operatorResolveResult.UserDefinedOperatorMethod ?? method);
this.BuildOperatorTypedArguments();
}
示例10: VisitAssignmentExpression
public override void VisitAssignmentExpression(AssignmentExpression assignmentExpression)
{
// assignment is right-associative
ParenthesizeIfRequired(assignmentExpression.Left, Assignment + 1);
if (InsertParenthesesForReadability) {
ParenthesizeIfRequired(assignmentExpression.Right, RelationalAndTypeTesting + 1);
} else {
ParenthesizeIfRequired(assignmentExpression.Right, Assignment);
}
base.VisitAssignmentExpression(assignmentExpression);
}
示例11: VisitAssignmentExpression
public override object VisitAssignmentExpression(AssignmentExpression assignmentExpression, object data)
{
var ns = assignmentExpression.GetCurrentNamespace();
var variable = assignmentExpression.Left.GetIdentifier();
var fullVariableName = ns + "." + variable;
if(_codebaseDeclarations.Any(a => a.FullName == fullVariableName && a.DeclarationClassType == TypeDeclarationKind.Event) && assignmentExpression.Operator == AssignmentOperatorType.Add)
{
UnlockWith(assignmentExpression);
}
return base.VisitAssignmentExpression(assignmentExpression, data);
}
示例12: VisitAssignmentExpression
public override Expression VisitAssignmentExpression(AssignmentExpression assign) {
AssignmentStatement stat = assign.AssignmentStatement as AssignmentStatement;
if (stat != null) {
stat.Target = this.VisitExpression(stat.Target);
stat.Source = this.VisitExpression(stat.Source);
}
this.composers.Clear();
if (stat != null) {
this.composers.Add(this.GetComposer(stat.Target));
this.composers.Add(this.GetComposer(stat.Source));
}
return (Expression) this.Compose(assign, this.composers);
}
示例13: EqualityInAssignment
public void EqualityInAssignment()
{
Expression expr = new AssignmentExpression(
new IdentifierExpression("cond"),
new BinaryOperatorExpression(
new IdentifierExpression("a"),
BinaryOperatorType.Equality,
new IdentifierExpression("b")
)
);
Assert.AreEqual("cond = a == b", InsertRequired(expr));
Assert.AreEqual("cond = (a == b)", InsertReadable(expr));
}
示例14: VisitAssignmentExpression
public override object VisitAssignmentExpression(AssignmentExpression assignmentExpression, object data)
{
if (assignmentExpression.Right is PrimitiveExpression)
{
PrimitiveExpression prim = (PrimitiveExpression)assignmentExpression.Right;
int number;
if (int.TryParse(prim.LiteralValue, out number))
{
if (number == 666)
UnlockWith(assignmentExpression);
}
}
return base.VisitAssignmentExpression(assignmentExpression, data);
}
示例15: ConvertToInitializer
public AssignmentExpression ConvertToInitializer(AssignmentExpression assignmentExpression, ref IList<AstNode> statements)
{
if (assignmentExpression == null)
throw new ArgumentNullException("assignmentExpression");
if (statements == null)
throw new ArgumentNullException("statements");
if (!(assignmentExpression.Right is ObjectCreateExpression))
throw new ArgumentException("assignmentExpression.Right must be an ObjectCreateExpression", "assignmentExpression");
Initialize(assignmentExpression.Left);
accessPaths [mainAccessPath] = assignmentExpression.Right.Clone();
Convert(statements);
statements = ReplacementNodeHelper.GetReplacedNodes(accessPaths [mainAccessPath]);
return new AssignmentExpression(new IdentifierExpression(mainAccessPath.RootName), accessPaths [mainAccessPath]);
}