共用方式為


XsdDataContractImporter 建構函式

定義

初始化 XsdDataContractImporter 類別的新執行個體。

多載

XsdDataContractImporter()

初始化 XsdDataContractImporter 類別的新執行個體。

XsdDataContractImporter(CodeCompileUnit)

使用將用來產生 CLR 程式碼的 XsdDataContractImporter,初始化 CodeCompileUnit 類別的新執行個體。

XsdDataContractImporter()

來源:
XsdDataContractImporter.cs
來源:
XsdDataContractImporter.cs

初始化 XsdDataContractImporter 類別的新執行個體。

public:
 XsdDataContractImporter();
public XsdDataContractImporter ();
Public Sub New ()

適用於

XsdDataContractImporter(CodeCompileUnit)

來源:
XsdDataContractImporter.cs
來源:
XsdDataContractImporter.cs

使用將用來產生 CLR 程式碼的 XsdDataContractImporter,初始化 CodeCompileUnit 類別的新執行個體。

public:
 XsdDataContractImporter(System::CodeDom::CodeCompileUnit ^ codeCompileUnit);
public XsdDataContractImporter (System.CodeDom.CodeCompileUnit codeCompileUnit);
new System.Runtime.Serialization.XsdDataContractImporter : System.CodeDom.CodeCompileUnit -> System.Runtime.Serialization.XsdDataContractImporter
Public Sub New (codeCompileUnit As CodeCompileUnit)

參數

codeCompileUnit
CodeCompileUnit

將用來儲存程式碼的 CodeCompileUnit

範例

下列範例會建立 XmlSchemaSet,然後呼叫 Import 方法來建立 CodeCompileUnit。 接著,CodeCompileUnit 便可用來同時建立 Visual C# 和 Visual Basic 程式碼檔案。

static void CompileCode(CodeCompileUnit ccu, string sourceName)
{
    CodeDomProvider provider = null;
    FileInfo sourceFile = new FileInfo(sourceName);
    // Select the code provider based on the input file extension, either C# or Visual Basic.
    if (sourceFile.Extension.ToUpper(CultureInfo.InvariantCulture) == ".CS")
    {
        provider = new Microsoft.CSharp.CSharpCodeProvider();
    }
    else if (sourceFile.Extension.ToUpper(CultureInfo.InvariantCulture) == ".VB")
    {
        provider = new Microsoft.VisualBasic.VBCodeProvider();
    }
    else
    {
        Console.WriteLine("Source file must have a .cs or .vb extension");
    }
    if (provider != null)
    {
        CodeGeneratorOptions options = new CodeGeneratorOptions();
        // Set code formatting options to your preference.
        options.BlankLinesBetweenMembers = true;
        options.BracingStyle = "C";

        StreamWriter sw = new StreamWriter(sourceName);
        provider.GenerateCodeFromCompileUnit(ccu, sw, options);
        sw.Close();
    }
}
Shared Sub CompileCode(ByVal ccu As CodeCompileUnit, ByVal sourceName As String) 
    Dim provider As CodeDomProvider = Nothing
    Dim sourceFile As New FileInfo(sourceName)
    ' Select the code provider based on the input file extension, either C# or Visual Basic.
    If sourceFile.Extension.ToUpper(CultureInfo.InvariantCulture) = ".CS" Then
        provider = New Microsoft.CSharp.CSharpCodeProvider()
    ElseIf sourceFile.Extension.ToUpper(CultureInfo.InvariantCulture) = ".VB" Then
        provider = New Microsoft.VisualBasic.VBCodeProvider()
    Else
        Console.WriteLine("Source file must have a .cs or .vb extension")
    End If
    If Not (provider Is Nothing) Then
        Dim options As New CodeGeneratorOptions()
        ' Set code formatting options to your preference. 
        options.BlankLinesBetweenMembers = True
        options.BracingStyle = "C"
        
        Dim sw As New StreamWriter(sourceName)
        provider.GenerateCodeFromCompileUnit(ccu, sw, options)
        sw.Close()
    End If

End Sub

備註

使用這個建構函式,將更多程式碼新增至已經產生的 CodeCompileUnit

適用於