【发布时间】:2015-04-09 17:19:15
【问题描述】:
我正在使用 CodeDom 生成一个结构
var type = new CodeTypeDeclaration();
type.Name = "MyStructure";
type.IsStruct = true;
type.TypeAttributes = TypeAttributes.Public;
type.Members.
type.Members.Add(new CodeMemberField{
Attributes = System.CodeDom.MemberAttributes.Public | System.CodeDom.MemberAttributes.Const,
Name = "CreatedBy",
Type = new CodeTypeReference(typeof (String)),
InitExpression = new CodePrimitiveExpression("createdby"),
});
type.Members.Add(new CodeMemberField{
Attributes = System.CodeDom.MemberAttributes.Public | System.CodeDom.MemberAttributes.Const,
Name = "ModifiedBy",
Type = new CodeTypeReference(typeof (String)),
InitExpression = new CodePrimitiveExpression("modifiedby")
});
当它生成时,它看起来像这样:
public struct MyStructure
{
public const string CreatedBy = "createdby";
public const string ModifiedBy = "modifiedby";
}
但我希望它没有换行符:
public struct MyStructure
{
public const string CreatedBy = "createdby";
public const string ModifiedBy = "modifiedby";
}
是否可以让生成不包含新行?
【问题讨论】:
-
查看stackoverflow.com/questions/238002/… 以获取以编程方式删除字符串中的换行符的示例。
-
@calmond 我必须让 CodeDom 生成文件,然后读取文件,然后只删除我想要删除的换行符,然后将文件写回磁盘。不是很好用的东西......