为了让CodeDom生成的类可被序列化,我在网上查了一下,方法:
只要给CodeTypeDeclaration对象添加一个CustomAttributes属性即可:
co.CustomAttributes.Add(new CodeAttributeDeclaration("Serializable"));
这样就可以在生成类前面加上"[Serializable()]",如图:
在codeProject上找到了这些CodeDom的源码,CodeDOM Strong Type Collection Maker :
遇到一个问题:生成的代码都有:
//------------------------------------------------------------------------------
// <autogenerated>
// This code was generated by a tool.
// Runtime Version: 1.1.4322.573
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </autogenerated>
//------------------------------------------------------------------------------
// <autogenerated>
// This code was generated by a tool.
// Runtime Version: 1.1.4322.573
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </autogenerated>
//------------------------------------------------------------------------------
不知道如何去掉?