XML XSD和serisliase反序列化c# [英] XML XSD and serisliase deserialise c#

查看:59
本文介绍了XML XSD和serisliase反序列化c#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

c#Null运算符中的XML XSD




推荐答案

只有类可以为null。 结构是值类型。如果你有一个可以为null的结构的要求,那么你必须将类型更改为T?。 但是您的盖子类型被定义为一个类,因此可以使用空值正常工作。

Only classes can be null.  Structs are value types. If you had a requirement for a nullable struct then you'd have to change the type to T?.  But your lid type is defined as a class and therefore will work just fine with a null value.

1)没有手册。  XSD是一种标准的XML格式,但您的代码没有使用它,因此无关紧要。当您要确保XML文件符合特定格式时,可以使用它。

1) There is no manual.  XSD is a standard XML format but your code isn't using it so it doesn't matter. It is used when you want to ensure that an XML file meets a specific format.

2)从XML读取时,空值很可能很好。问题是你的代码很可能不会期望它为空,因此会爆炸。  XML序列化器应该没问题。

2) The null values are most likely fine when read from the XML. The issue is that your code is most likely not expecting it to be null and therefore blowing up.  The XML serializer should be just fine.

您已经发布了XML和生成的类型信息,但是您没有提供任何关于您获得的异常,触发它的调用堆栈以及异常时正在执行的代码。我们需要这个
了解失败的地方。另请注意,如果XML允许盖子为null,那么您的代码也需要在序列化后处理该案例。

You've posted the XML and generated type information but you haven't provided use with any information on what exception you're getting, the callstack that triggered it and the code that was being executed at the time of the exception. We'll need this to understand where the failure is. Also note that if the XML allows a lid to be null then your code needs to handle that case after serialization as well.

Michael Taylor

http:// blogs.msmvps.com/p3net

Michael Taylor
http://blogs.msmvps.com/p3net


这篇关于XML XSD和serisliase反序列化c#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆