本文主要是介绍让CodeDom生成的类可序列化,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
为了让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>
// ------------------------------------------------------------------------------
不知道如何去掉?
这篇关于让CodeDom生成的类可序列化的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!