/// <summary> /// 変換メソッド:switch /// </summary> /// <param name="item">C#解析結果</param> /// <param name="config">設定情報</param> /// <param name="indent">インデント数</param> /// <param name="otherScripts">その他のスクリプト(内部クラスなど)</param> /// <returns>TypeScript変換結果</returns> private string Convert(IItemSwitch item, Config config, int indent, List <string> otherScripts) { var result = new StringBuilder(); var indentSpace = GetIndentSpace(indent); // コメント result.Append(GetTypeScriptComments(item, indentSpace)); // caseがtypeチェックとローカルフィールド設定か否か var existsTypes = item.Cases.Where(caseItem => ExistsTypeCase(caseItem as IItemSwitchCase)).Any(); if (!existsTypes) { // 定義(switchのみ) result.AppendLine($"{indentSpace}switch ({ExpressionsToString(item.Conditions)}) {{"); // caseはインデントをインクリメント indent++; } // メンバー追加 foreach (var member in item.Cases) { result.Append(ConvertUtility.Convert(member, config, indent, otherScripts)); } if (!existsTypes) { // 定義(switchのみ) result.AppendLine($"{indentSpace}}}"); } return(result.ToString()); }
/// <summary> /// Switchステートメントの確認 /// </summary> /// <param name="target">対象インスタンス</param> /// <param name="condition">条件式</param> /// <param name="caseCount">case数</param> /// <returns></returns> private bool checkSwitch(IItemSwitch target, string condition, int caseCount) { Assert.NotNull(target); Assert.Equal(condition, GetExpressionsToString(target.Conditions)); Assert.Equal(caseCount, target.Cases.Count); return(true); }