/// <summary> /// 構文のTypeScript変換 /// </summary> /// <param name="index">インデックス数</param> /// <param name="localDeclarationStatements">宣言済ローカル変数のリスト</param> /// <returns>TypeScriptに変換した文字列</returns> public override string ConvertStatement(int index, List <string> localDeclarationStatements) { var statement = Statement as WhileStatementSyntax; var result = new StringBuilder(); var spaceIndex = GetSpace(index); result.AppendLine($"{spaceIndex}while ({ExpressionsInstance.GetExpression(statement.Condition, localDeclarationStatements)})" + " {"); result.Append(MethodInstance.GetMethodText(statement.Statement as BlockSyntax, index + IndentSize, localDeclarationStatements)); result.AppendLine(spaceIndex + "}"); return(result.ToString()); }
/// <summary> /// 構文のTypeScript変換 /// </summary> /// <param name="index">インデックス数</param> /// <param name="localDeclarationStatements">宣言済ローカル変数のリスト</param> /// <returns>TypeScriptに変換した文字列</returns> public override string ConvertStatement(int index, List <string> localDeclarationStatements) { var statement = Statement as LocalFunctionStatementSyntax; var classObject = ClassObject.GetInstance(); var result = new StringBuilder(); var spaceIndex = GetSpace(index); // 一時的なローカル変数とメソッドパラメータを作成 var methodParams = new List <string>(); var tempLocalDeclarationStatements = new List <string>(); tempLocalDeclarationStatements.AddRange(localDeclarationStatements); foreach (var v in statement.ParameterList.Parameters) { tempLocalDeclarationStatements.Add(v.Identifier.ValueText); var methodParam = $"{v.Identifier.ValueText}: {classObject.GetTypeScriptType(v.Type)}"; if (v.Default != null) { methodParam += " = " + ExpressionsInstance.GetExpression(v.Default.Value, tempLocalDeclarationStatements); } methodParams.Add(methodParam); } // 構文作成 result.AppendLine($"{spaceIndex}let {statement.Identifier.Text} = ({string.Join(", ",methodParams)}): {classObject.GetTypeScriptType(statement.ReturnType)} => {{"); if (statement.Body == null) { result.AppendLine($"{GetSpace(index + IndentSize)}return {ExpressionsInstance.GetExpression(statement.ExpressionBody.Expression, tempLocalDeclarationStatements)};"); } else { result.Append(MethodInstance.GetMethodText(statement.Body as BlockSyntax, index + IndentSize, tempLocalDeclarationStatements)); } result.AppendLine(spaceIndex + "}"); return(result.ToString()); }
/// <summary> /// 構文のTypeScript変換 /// </summary> /// <param name="index">インデックス数</param> /// <param name="localDeclarationStatements">宣言済ローカル変数のリスト</param> /// <returns>TypeScriptに変換した文字列</returns> public override string ConvertStatement(int index, List <string> localDeclarationStatements) { var statement = Statement as SwitchStatementSyntax; var result = new StringBuilder(); var spaceIndex = GetSpace(index); result.Append(spaceIndex); result.AppendLine($"switch ({ExpressionsInstance.GetExpression(statement.Expression, localDeclarationStatements)})" + " {"); foreach (var section in statement.Sections) { foreach (var label in section.Labels) { result.AppendLine($"{GetSpace(index + IndentSize)}{label}"); } result.Append(MethodInstance.GetMethodText(section.Statements, index + 4, localDeclarationStatements)); } result.AppendLine(spaceIndex + "}"); return(result.ToString()); }
/// <summary> /// 構文のTypeScript変換 /// </summary> /// <param name="index">インデックス数</param> /// <param name="localDeclarationStatements">宣言済ローカル変数のリスト</param> /// <returns>TypeScriptに変換した文字列</returns> public override string ConvertStatement(int index, List <string> localDeclarationStatements) { var statement = Statement as ForStatementSyntax; var result = new StringBuilder(); var spaceIndex = GetSpace(index); // 一時的なローカル変数を作成 var tempLocalDeclarationStatements = new List <string>(); tempLocalDeclarationStatements.AddRange(localDeclarationStatements); foreach (var v in statement.Declaration.Variables) { tempLocalDeclarationStatements.Add(v.Identifier.ValueText); } // 構文作成 result.AppendLine($"{spaceIndex}for (let {statement.Declaration.Variables}; {ExpressionsInstance.GetExpression(statement.Condition, tempLocalDeclarationStatements)}; {statement.Incrementors})" + " {"); result.Append(MethodInstance.GetMethodText(statement.Statement as BlockSyntax, index + IndentSize, tempLocalDeclarationStatements)); result.AppendLine(spaceIndex + "}"); return(result.ToString()); }
/// <summary> /// 構文のTypeScript変換 /// </summary> /// <param name="index">インデックス数</param> /// <param name="localDeclarationStatements">宣言済ローカル変数のリスト</param> /// <returns>TypeScriptに変換した文字列</returns> public override string ConvertStatement(int index, List <string> localDeclarationStatements) { var statement = Statement as ForEachStatementSyntax; var result = new StringBuilder(); var spaceIndex = GetSpace(index); // 一時的なローカル変数を作成 var tempLocalDeclarationStatements = new List <string>(); tempLocalDeclarationStatements.AddRange(localDeclarationStatements); if (!tempLocalDeclarationStatements.Contains(statement.Identifier.ToString())) { tempLocalDeclarationStatements.Add(statement.Identifier.ToString()); } // 構文作成 result.AppendLine($"{spaceIndex}for (let {statement.Identifier} in {ExpressionsInstance.GetExpression(statement.Expression, tempLocalDeclarationStatements)})" + " {"); result.Append(MethodInstance.GetMethodText(statement.Statement as BlockSyntax, index + IndentSize, tempLocalDeclarationStatements)); result.AppendLine(spaceIndex + "}"); return(result.ToString()); }