题
有没有办法用CodeDom生成类约束。
因为当我使用像
这样的东西时var method = new CodeMemberMethod();
var genericParam = new CodeTypeParameter("InterfaceType");
genericParam.Constraints.Add("class");
method.TypeParameters.Add(genericParam);
生成的代码就像
private InterfaceType GetImpl<InterfaceType>()
where InterfaceType : @class
{
}
我找到的最佳解决方法是在课程之前使用前导空格
genericParam.Constraints.Add(" class");
但这似乎充其量只是一种解决方法。
其他提示
我还使用零宽度空间(&quot; \ x200Bclass&quot;
)而不是普通空间。然后我在最后一个字符串中用空字符串替换它: .Replace(&quot; \ x200B&quot;,string.Empty);
不隶属于 StackOverflow