IXmlSerializable.GetSchema 方法

定义

此方法是保留方法,请不要使用。This method is reserved and should not be used. 在实现 IXmlSerializable 接口时,应从此方法返回 null(在 Visual Basic 中为 Nothing),如果需要指定自定义架构,应向该类应用 XmlSchemaProviderAttributeWhen implementing the IXmlSerializable interface, you should return null (Nothing in Visual Basic) from this method, and instead, if specifying a custom schema is required, apply the XmlSchemaProviderAttribute to the class.

public:
 System::Xml::Schema::XmlSchema ^ GetSchema();
public System.Xml.Schema.XmlSchema GetSchema ();
abstract member GetSchema : unit -> System.Xml.Schema.XmlSchema
Public Function GetSchema () As XmlSchema

返回

一个 XmlSchema,描述由 WriteXml(XmlWriter) 方法生成并由 ReadXml(XmlReader) 方法使用的对象的 XML 表示形式。An XmlSchema that describes the XML representation of the object that is produced by the WriteXml(XmlWriter) method and consumed by the ReadXml(XmlReader) method.

注解

序列化或反序列化对象时,XmlSerializer 类不执行 XML 验证。When serializing or deserializing an object, the XmlSerializer class does not perform XML validation. 出于此原因,通过提供此方法的简单实现(例如,通过返回 nullNothing 在 Visual Basic 中),通常可以安全地省略架构信息。For this reason, it is often safe to omit schema information by providing a trivial implementation of this method, for example by returning null (Nothing in Visual Basic).

如果需要提供架构信息,则应使用 XmlSchemaProviderAttribute 特性。If providing schema information is necessary, you should use the XmlSchemaProviderAttribute attribute. GetSchema 方法仍应返回 null (或 Nothing)。The GetSchema method should still return null (or Nothing).

某些 .NET Framework.NET Framework 类型以及实现 IXmlSerializable 接口的旧自定义类型可能使用 GetSchema,而不是 XmlSchemaProviderSome .NET Framework.NET Framework types as well as legacy custom types implementing the IXmlSerializable interface may be using GetSchema instead of XmlSchemaProvider. 在这种情况下,方法会返回准确的 XML 架构,该架构描述 WriteXml 方法所生成的对象的 XML 表示形式。In this case, the method returns an accurate XML schema that describes the XML representation of the object generated by the WriteXml method.

适用于