Я генерируя-структуру, используя CodeDomКак предотвратить CodeMemberField от вставки новой строки?
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";
}
Возможно ли, чтобы генерация не включала новые строки?
Заканчивать http://stackoverflow.com/questions/238002/replace-line-breaks-in-a-string-c-sharp для примера программно удаления новой строки в строке. – calmond
@calmond Мне нужно будет предоставить CodeDom Generate File, затем прочитать файл, а затем удалить только новые строки, которые я хочу удалить, записать файл обратно на диск. Не то, что будет работать очень хорошо ... – Daryl