【发布时间】:2020-10-15 21:22:37
【问题描述】:
我正在尝试将一些代码添加到这样的代码字符串中
public static string Compile(string code)
{
Write("compiler called.");
/////////////Below is the string I want to interpolate//////////////
string codeToCompile = $@"
using System;
namespace RoslynCompileSample
{
public class Writer
{
public string Write()
{
{code}
}
}
}";
///////////////// Other Codes...//////////////////////////
【问题讨论】:
-
抱歉打错了,因为没有
code变量,code' 是方法的参数,让我来解决这个问题。 -
为什么要使用内插字符串?您似乎不需要对该字符串进行插值,并且 C# 自然包含 { } 作为其范围的一部分这一事实意味着它破坏了您不需要的插值