/// <summary> /// 文字列取得 /// </summary> /// <param name="index">前スペース数</param> /// <returns>文字列</returns> public override string ToString(int index = 0) { var result = new StringBuilder(); var indexSpace = string.Concat(Enumerable.Repeat(" ", index)); // インデックススペースを作成 result.Append(indexSpace); // 左辺の作成 if (LeftSideList.Any()) { result.Append(GetSideExpressionList(LeftSideList)); } // 代入演算子 if (!string.IsNullOrEmpty(AssignmentOperator)) { result.Append($" {AssignmentOperator} "); } // 右辺の作成 if (RightSideList.Any()) { result.Append(GetSideExpressionList(RightSideList)); } result.Append(";"); return result.ToString(); }
public override bool MoveStaff(FarmersStuff farmersStuff) { if (isOnLeftSide) { if (LeftSideList.Where(arg => arg == farmersStuff).Count() > 0) { LeftSideList.Remove(farmersStuff); RightSideList.Add(farmersStuff); return(true); } return(false); } else { throw new Exception("Farmer is on other side"); } }
/// <summary> /// 初期化 /// </summary> /// <param name="node">対象Node</param> /// <param name="semanticModel">対象ソースのsemanticModel</param> /// <param name="parent">親IAnalyzeItem</param> private void Initialize(SyntaxNode node, SemanticModel semanticModel, IAnalyzeItem parent) { ItemType = ItemTypes.MethodStatement; // 処理内容を取得 IOperation operation = null; if (node is ExpressionStatementSyntax expressionStatement) { operation = semanticModel.GetOperation(expressionStatement.Expression); } else { operation = semanticModel.GetOperation(node); } // 式情報を取得 switch (operation) { case ISimpleAssignmentOperation param: LeftSideList.AddRange(OperationFactory.GetExpressionList(param.Target, eventContainer)); RightSideList.AddRange(OperationFactory.GetExpressionList(param.Value, eventContainer)); break; case IInvocationOperation param: RightSideList.AddRange(OperationFactory.GetExpressionList(param, eventContainer)); break; case IPropertyReferenceOperation param: RightSideList.AddRange(OperationFactory.GetExpressionList(param, eventContainer)); break; case ILocalReferenceOperation param: RightSideList.AddRange(OperationFactory.GetExpressionList(param, eventContainer)); break; case ILiteralOperation param: RightSideList.AddRange(OperationFactory.GetExpressionList(param, eventContainer)); break; case IFieldReferenceOperation param: RightSideList.AddRange(OperationFactory.GetExpressionList(param, eventContainer)); break; case IInstanceReferenceOperation param: RightSideList.AddRange(OperationFactory.GetExpressionList(param, eventContainer)); break; case ICompoundAssignmentOperation param: LeftSideList.AddRange(OperationFactory.GetExpressionList(param.Target, eventContainer)); RightSideList.AddRange(OperationFactory.GetExpressionList(param.Value, eventContainer)); break; case IIncrementOrDecrementOperation param: var target = OperationFactory.GetExpressionList(param.Target, eventContainer); if(param.IsPostfix){ RightSideList.AddRange(target); } switch (param.Kind) { case OperationKind.Increment: RightSideList.Add(new Expression("++", string.Empty)); break; case OperationKind.Decrement: RightSideList.Add(new Expression("--", string.Empty)); break; } if (!param.IsPostfix) { RightSideList.AddRange(target); } break; default: Console.Write($" [{operation.Kind} is none] "); break; } // 代入演算子 if(node is AssignmentExpressionSyntax assignmentExpression) { AssignmentOperator = assignmentExpression.OperatorToken.Text; } }