XsdDataContractImporter Konstruktory
Definicja
Ważne
Niektóre informacje odnoszą się do produktu w wersji wstępnej, który może zostać znacząco zmodyfikowany przed wydaniem. Firma Microsoft nie udziela żadnych gwarancji, jawnych lub domniemanych, w odniesieniu do informacji podanych w tym miejscu.
Inicjuje nowe wystąpienie klasy XsdDataContractImporter.
Przeciążenia
XsdDataContractImporter() |
Inicjuje nowe wystąpienie klasy XsdDataContractImporter. |
XsdDataContractImporter(CodeCompileUnit) |
Inicjuje XsdDataContractImporter nowe wystąpienie klasy za CodeCompileUnit pomocą klasy , która będzie służyć do generowania kodu CLR. |
XsdDataContractImporter()
Inicjuje nowe wystąpienie klasy XsdDataContractImporter.
public:
XsdDataContractImporter();
public XsdDataContractImporter ();
Public Sub New ()
Dotyczy
XsdDataContractImporter(CodeCompileUnit)
Inicjuje XsdDataContractImporter nowe wystąpienie klasy za CodeCompileUnit pomocą klasy , która będzie służyć do generowania kodu CLR.
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)
Parametry
- codeCompileUnit
- CodeCompileUnit
Element CodeCompileUnit , który będzie używany do przechowywania kodu.
Przykłady
Poniższy przykład tworzy metodę XmlSchemaSet i wywołuje metodę Import w celu utworzenia CodeCompileUnitklasy . Element CodeCompileUnit jest następnie używany do tworzenia plików kodu Visual C# i 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
Uwagi
Użyj tego konstruktora, aby dodać więcej kodu do CodeCompileUnit elementu, który został już wygenerowany.
Dotyczy
Opinia
https://aka.ms/ContentUserFeedback.
Dostępne już wkrótce: W 2024 r. będziemy stopniowo wycofywać zgłoszenia z serwisu GitHub jako mechanizm przesyłania opinii na temat zawartości i zastępować go nowym systemem opinii. Aby uzyskać więcej informacji, sprawdź:Prześlij i wyświetl opinię dla