다음을 통해 공유


XsdDataContractImporter 생성자

정의

XsdDataContractImporter 클래스의 새 인스턴스를 초기화합니다.

오버로드

XsdDataContractImporter()

XsdDataContractImporter 클래스의 새 인스턴스를 초기화합니다.

XsdDataContractImporter(CodeCompileUnit)

CLR 코드를 생성하는 데 사용할 XsdDataContractImporter을 사용하여 CodeCompileUnit 클래스의 새 인스턴스를 초기화합니다.

XsdDataContractImporter()

Source:
XsdDataContractImporter.cs
Source:
XsdDataContractImporter.cs
Source:
XsdDataContractImporter.cs

XsdDataContractImporter 클래스의 새 인스턴스를 초기화합니다.

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

적용 대상

XsdDataContractImporter(CodeCompileUnit)

Source:
XsdDataContractImporter.cs
Source:
XsdDataContractImporter.cs
Source:
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에 코드를 추가합니다.

적용 대상