public override templateExpression()

in src/languages/csharp.ts [604:622]


  public override templateExpression(node: ts.TemplateExpression, context: CSharpRenderer): OTree {
    // If this is a multi-line string literal, we need not quote much, as @"string" literals in C#
    // do not perform any quoting. The literal quotes in the text however must be doubled.
    const isMultiLine =
      !!node.head.rawText?.includes('\n') || node.templateSpans.some((span) => span.literal.rawText?.includes('\n'));

    const parts = new Array<string>();
    if (node.head.rawText) {
      parts.push(isMultiLine ? node.head.rawText.replace(/"/g, '""') : quoteStringLiteral(node.head.rawText));
    }
    for (const span of node.templateSpans) {
      parts.push(`{${context.textOf(span.expression)}}`);
      if (span.literal.rawText) {
        parts.push(isMultiLine ? span.literal.rawText.replace(/"/g, '""') : quoteStringLiteral(span.literal.rawText));
      }
    }

    return new OTree([isMultiLine ? '$@"' : '$"', ...parts, '"']);
  }