/// <summary> /// 変換メソッド:if /// </summary> /// <param name="item">C#解析結果</param> /// <param name="config">設定情報</param> /// <param name="indent">インデント数</param> /// <param name="otherScripts">その他のスクリプト(内部クラスなど)</param> /// <returns>TypeScript変換結果</returns> private string Convert(IItemIf item, Config config, int indent, List <string> otherScripts) { var result = new StringBuilder(); var indentSpace = GetIndentSpace(indent); // コメント result.Append(GetTypeScriptComments(item, indentSpace)); // 定義 result.AppendLine($"{indentSpace}if ({ConvertConditions(item.Conditions)}) {{"); // メンバー追加 foreach (var member in item.TrueBlock) { result.Append(ConvertUtility.Convert(member, config, indent + 1, otherScripts)); } result.AppendLine($"{indentSpace}}}"); // else構文追加 foreach (var block in item.FalseBlocks) { result.Append(ConvertUtility.Convert(block, config, indent, otherScripts)); } return(result.ToString()); }
/// <summary> /// IFステートメントの確認 /// </summary> /// <param name="target">対象インスタンス</param> /// <param name="condition">条件式</param> /// <param name="existElseBlock">else数</param> /// <returns></returns> private bool checkIf(IItemIf target, string condition, int elseBlockCount) { Assert.NotNull(target); Assert.Equal(condition, GetExpressionsToString(target.Conditions)); Assert.Equal(elseBlockCount, target.FalseBlocks.Count); return(true); }