本文整理匯總了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;
}
}