序列化 BigInteger
是否有任何方法可以将 BigInteger 序列化到 XML 文件或从 XML 文件序列化 BigInteger?
下面是一个简短的片段,演示了我当前如何序列化类:
static public void SerializeToXML( Report report )
{
XmlSerializer serializer = new XmlSerializer( typeof( Report ) );
using ( TextWriter textWriter = new StreamWriter( Path.Combine( report.Path, report.Filename ) ) )
{
serializer.Serialize( textWriter, report );
}
}
[Serializable]
public class Report
{
public BigInteger CurrentMaximum { get; set; }
}
Report 类中的所有其他属性都已正确序列化,但是 BigInteger 属性却没有。有没有办法序列化这个属性?
Is there any method of serializing a BigInteger to and from an XML file?
Below is a short snippet that demonstrates how I'm currently serializing classes:
static public void SerializeToXML( Report report )
{
XmlSerializer serializer = new XmlSerializer( typeof( Report ) );
using ( TextWriter textWriter = new StreamWriter( Path.Combine( report.Path, report.Filename ) ) )
{
serializer.Serialize( textWriter, report );
}
}
[Serializable]
public class Report
{
public BigInteger CurrentMaximum { get; set; }
}
All other properties within the Report class get serialized correctly, however, the BigInteger properties do not. Is there a way to serialize this property?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不幸的是,
XmlSerializer
旨在创建可使用标准 XML 架构描述的 XML; .Net 1.0 阶段框架中的内容(这意味着 xs:integer)。IXmlSerialized
您需要修改
BigInteger
类并向其添加IXmlSerialized
接口。如果您需要使用 XSD 往返(例如 WebService 引用),这可能会导致问题。代理属性 (虽然这看起来有代码味道,但它更便携)
使用受支持的架构类型(最有可能是 xs:string)创建一个新属性并隐藏来自智能感知。
Unfortunately
XmlSerializer
is designed to create XML describeable using a standard XML Schema; that were in the framework during the .Net 1.0 phase (which means xs:integer isn't supported).IXmlSerializable
You will need to modify the
BigInteger
class and add theIXmlSerializable
interface to it. If you need to use XSD round-tripping (e.g. WebService references) this might cause problems.Proxy Property (Although this looks like it has code-smell it is way more portable)
Create a new property with a supported schema type (most probably xs:string) and hide it from intellisense.