本文整理汇总了C#中System.Runtime.Serialization.ExportOptions类的典型用法代码示例。如果您正苦于以下问题:C# ExportOptions类的具体用法?C# ExportOptions怎么用?C# ExportOptions使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ExportOptions类属于System.Runtime.Serialization命名空间,在下文中一共展示了ExportOptions类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
//引入命名空间
using System;
using System.Xml;
using System.Runtime.Serialization;
using System.Xml.Schema;
public class Program
{
public static void Main()
{
try
{
ExportXSD();
}
catch (Exception exc)
{
Console.WriteLine("Message: {0} StackTrace:{1}", exc.Message, exc.StackTrace);
}
finally
{
Console.ReadLine();
}
}
static void ExportXSD()
{
XsdDataContractExporter exporter = new XsdDataContractExporter();
if (exporter.CanExport(typeof(Employee)))
{
exporter.Export(typeof(Employee));
Console.WriteLine("number of schemas: {0}", exporter.Schemas.Count);
Console.WriteLine();
XmlSchemaSet mySchemas = exporter.Schemas;
XmlQualifiedName XmlNameValue = exporter.GetRootElementName(typeof(Employee));
string EmployeeNameSpace = XmlNameValue.Namespace;
foreach (XmlSchema schema in mySchemas.Schemas(EmployeeNameSpace))
{
schema.Write(Console.Out);
}
}
}
static void GetXmlElementName()
{
XsdDataContractExporter myExporter = new XsdDataContractExporter();
XmlQualifiedName xmlElementName =myExporter.GetRootElementName(typeof(Employee));
Console.WriteLine("Namespace: {0}", xmlElementName.Namespace);
Console.WriteLine("Name: {0}", xmlElementName.Name);
Console.WriteLine("IsEmpty: {0}", xmlElementName.IsEmpty);
}
[DataContract(Namespace = "www.Contoso.com/Examples/")]
public class Employee
{
[DataMember]
public string EmployeeName;
[DataMember]
private string ID;
}
}