XsdDataContractExporter.CanExport 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
會取得一個值,指示是否可以匯出一個通用語言執行時(CLR)型別(或一組型別)。
多載
| 名稱 | Description |
|---|---|
| CanExport(ICollection<Assembly>) |
會取得一個值,指示是否能匯出一組組合語言中的 .common language runtime(CLR)型別集合。 |
| CanExport(ICollection<Type>) |
會取得一個值,指示是否能匯出包含在 a ICollection<T> 中的 .common language runtime(CLR)型別集合。 |
| CanExport(Type) |
會取得一個值,指示是否可以匯出指定的通用語言執行時(CLR)型態。 |
備註
並非所有 CLR 類型都能用於資料合約。 欲了解更多可序列化的資訊,請參閱 資料合約序列化器支援的類型。
CanExport(ICollection<Assembly>)
會取得一個值,指示是否能匯出一組組合語言中的 .common language runtime(CLR)型別集合。
public:
bool CanExport(System::Collections::Generic::ICollection<System::Reflection::Assembly ^> ^ assemblies);
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed.")]
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
public bool CanExport(System.Collections.Generic.ICollection<System.Reflection.Assembly> assemblies);
public bool CanExport(System.Collections.Generic.ICollection<System.Reflection.Assembly> assemblies);
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
public bool CanExport(System.Collections.Generic.ICollection<System.Reflection.Assembly> assemblies);
[<System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed.")>]
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")>]
member this.CanExport : System.Collections.Generic.ICollection<System.Reflection.Assembly> -> bool
member this.CanExport : System.Collections.Generic.ICollection<System.Reflection.Assembly> -> bool
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")>]
member this.CanExport : System.Collections.Generic.ICollection<System.Reflection.Assembly> -> bool
Public Function CanExport (assemblies As ICollection(Of Assembly)) As Boolean
參數
- assemblies
- ICollection<Assembly>
其中 A ICollection<T>Assembly 包含要匯出的 Assembly 及類型。
傳回
true若類型可匯出;否則,。 false
- 屬性
適用於
CanExport(ICollection<Type>)
會取得一個值,指示是否能匯出包含在 a ICollection<T> 中的 .common language runtime(CLR)型別集合。
public:
bool CanExport(System::Collections::Generic::ICollection<Type ^> ^ types);
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed.")]
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
public bool CanExport(System.Collections.Generic.ICollection<Type> types);
public bool CanExport(System.Collections.Generic.ICollection<Type> types);
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
public bool CanExport(System.Collections.Generic.ICollection<Type> types);
[<System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed.")>]
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")>]
member this.CanExport : System.Collections.Generic.ICollection<Type> -> bool
member this.CanExport : System.Collections.Generic.ICollection<Type> -> bool
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")>]
member this.CanExport : System.Collections.Generic.ICollection<Type> -> bool
Public Function CanExport (types As ICollection(Of Type)) As Boolean
參數
- types
- ICollection<Type>
ICollection<T> A 包含要匯出的指定類型。
傳回
true若類型可匯出;否則,。 false
- 屬性
適用於
CanExport(Type)
會取得一個值,指示是否可以匯出指定的通用語言執行時(CLR)型態。
public:
bool CanExport(Type ^ type);
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed.")]
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
public bool CanExport(Type type);
public bool CanExport(Type type);
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
public bool CanExport(Type type);
[<System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed.")>]
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")>]
member this.CanExport : Type -> bool
member this.CanExport : Type -> bool
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")>]
member this.CanExport : Type -> bool
Public Function CanExport (type As Type) As Boolean
參數
傳回
true若類型可輸出;否則,。 false
- 屬性
範例
以下範例在呼叫CanExport(Type)方法之前,先呼叫該Export(Type)方法。
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);
}
}
}
Shared Sub ExportXSD()
Dim exporter As New XsdDataContractExporter()
' Use the ExportOptions to add the Possessions type to the
' collection of KnownTypes.
Dim eOptions As New ExportOptions()
eOptions.KnownTypes.Add(GetType(Possessions))
exporter.Options = eOptions
If exporter.CanExport(GetType(Employee)) Then
exporter.Export(GetType(Employee))
Console.WriteLine("number of schemas: {0}", exporter.Schemas.Count)
Console.WriteLine()
Dim mySchemas As XmlSchemaSet = exporter.Schemas
Dim XmlNameValue As XmlQualifiedName = _
exporter.GetRootElementName(GetType(Employee))
Dim EmployeeNameSpace As String = XmlNameValue.Namespace
Dim schema As XmlSchema
For Each schema In mySchemas.Schemas(EmployeeNameSpace)
schema.Write(Console.Out)
Next schema
End If
End Sub