UNPKG

@microsoft.azure/autorest.incubator

Version:
41 lines 1.46 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const initializer_1 = require("../../../common/initializer"); const text_manipulation_1 = require("../../../common/text-manipulation"); const expression_1 = require("../../../csharp/code-dom/expression"); const case_1 = require("../../../csharp/code-dom/statements/case"); function Switch(expression, cases, objectInitializer) { return new SwitchStatement(expression_1.toExpression(expression), cases, objectInitializer); } exports.Switch = Switch; class SwitchStatement extends initializer_1.Initializer { constructor(expression, cases, objectInitializer) { super(); this.expression = expression; this.caseStatements = new Array(); this.apply(objectInitializer); this.add(cases); } get implementation() { return ` switch ( ${this.expression.value} ) { ${text_manipulation_1.indent(this.caseStatements.map(each => each.implementation).join(text_manipulation_1.EOL))} }`; } add(cases) { if (typeof cases === 'function') { cases = cases(); } if (cases instanceof case_1.CaseStatement) { this.caseStatements.push(cases); } else { for (const caseStatement of cases) { this.caseStatements.push(caseStatement); } } } } exports.SwitchStatement = SwitchStatement; //# sourceMappingURL=switch.js.map