SoapEnumAttribute Costruttori
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Inizializza una nuova istanza della classe SoapEnumAttribute.
Overload
SoapEnumAttribute() |
Inizializza una nuova istanza della classe SoapEnumAttribute. |
SoapEnumAttribute(String) |
Inizializza una nuova istanza della classe SoapEnumAttribute usando il nome di elemento specificato. |
SoapEnumAttribute()
Inizializza una nuova istanza della classe SoapEnumAttribute.
public:
SoapEnumAttribute();
public SoapEnumAttribute ();
Public Sub New ()
Esempio
Nell'esempio seguente viene utilizzato per XmlSerializer serializzare una classe denominata Food
che include un'enumerazione denominata FoodType
. L'enumerazione FoodType
viene sottoposta a override creando un SoapEnumAttribute oggetto per ogni enumerazione e impostando la SoapEnum proprietà di un SoapAttributes oggetto su SoapEnumAttribute. L'oggetto SoapAttributes viene aggiunto a un SoapAttributeOverrides oggetto utilizzato per creare un oggetto XmlSerializer.
#using <System.Xml.dll>
#using <System.dll>
using namespace System;
using namespace System::IO;
using namespace System::Xml;
using namespace System::Xml::Serialization;
public enum class GroupType
{
// Use the SoapEnumAttribute to instruct the XmlSerializer
// to generate Small and Large instead of A and B.
[SoapEnum("Small")]
A,
[SoapEnum("Large")]
B
};
public ref class Group
{
public:
String^ GroupName;
GroupType Grouptype;
};
public ref class Run
{
public:
void SerializeObject( String^ filename )
{
// Create an instance of the XmlSerializer Class.
XmlTypeMapping^ mapp = (gcnew SoapReflectionImporter)->ImportTypeMapping( Group::typeid );
XmlSerializer^ mySerializer = gcnew XmlSerializer( mapp );
// Writing the file requires a TextWriter.
TextWriter^ writer = gcnew StreamWriter( filename );
// Create an instance of the Class that will be serialized.
Group^ myGroup = gcnew Group;
// Set the Object* properties.
myGroup->GroupName = ".NET";
myGroup->Grouptype = GroupType::A;
// Serialize the Class, and close the TextWriter.
mySerializer->Serialize( writer, myGroup );
writer->Close();
}
void SerializeOverride( String^ fileName )
{
SoapAttributeOverrides^ soapOver = gcnew SoapAttributeOverrides;
SoapAttributes^ SoapAtts = gcnew SoapAttributes;
// Add a SoapEnumAttribute for the GroupType::A enumerator.
// Instead of 'A' it will be S"West".
SoapEnumAttribute^ soapEnum = gcnew SoapEnumAttribute( "West" );
// Override the S"A" enumerator.
SoapAtts->GroupType::SoapEnum = soapEnum;
soapOver->Add( GroupType::typeid, "A", SoapAtts );
// Add another SoapEnumAttribute for the GroupType::B enumerator.
// Instead of //B// it will be S"East".
SoapAtts = gcnew SoapAttributes;
soapEnum = gcnew SoapEnumAttribute;
soapEnum->Name = "East";
SoapAtts->GroupType::SoapEnum = soapEnum;
soapOver->Add( GroupType::typeid, "B", SoapAtts );
// Create an XmlSerializer used for overriding.
XmlTypeMapping^ map = (gcnew SoapReflectionImporter( soapOver ))->ImportTypeMapping( Group::typeid );
XmlSerializer^ ser = gcnew XmlSerializer( map );
Group^ myGroup = gcnew Group;
myGroup->GroupName = ".NET";
myGroup->Grouptype = GroupType::B;
// Writing the file requires a TextWriter.
TextWriter^ writer = gcnew StreamWriter( fileName );
ser->Serialize( writer, myGroup );
writer->Close();
}
};
int main()
{
Run^ test = gcnew Run;
test->SerializeObject( "SoapEnum.xml" );
test->SerializeOverride( "SoapOverride.xml" );
Console::WriteLine( "Fininished writing two files" );
}
using System;
using System.IO;
using System.Xml;
using System.Xml.Serialization;
public class Group{
public string GroupName;
public GroupType Grouptype;
}
public enum GroupType{
// Use the SoapEnumAttribute to instruct the XmlSerializer
// to generate Small and Large instead of A and B.
[SoapEnum("Small")]
A,
[SoapEnum("Large")]
B
}
public class Run {
static void Main(){
Run test= new Run();
test.SerializeObject("SoapEnum.xml");
test.SerializeOverride("SoapOverride.xml");
Console.WriteLine("Fininished writing two files");
}
private void SerializeObject(string filename){
// Create an instance of the XmlSerializer Class.
XmlTypeMapping mapp =
(new SoapReflectionImporter()).ImportTypeMapping(typeof(Group));
XmlSerializer mySerializer = new XmlSerializer(mapp);
// Writing the file requires a TextWriter.
TextWriter writer = new StreamWriter(filename);
// Create an instance of the Class that will be serialized.
Group myGroup = new Group();
// Set the object properties.
myGroup.GroupName = ".NET";
myGroup.Grouptype= GroupType.A;
// Serialize the Class, and close the TextWriter.
mySerializer.Serialize(writer, myGroup);
writer.Close();
}
private void SerializeOverride(string fileName){
SoapAttributeOverrides soapOver = new SoapAttributeOverrides();
SoapAttributes SoapAtts = new SoapAttributes();
// Add a SoapEnumAttribute for the GroupType.A enumerator.
// Instead of 'A' it will be "West".
SoapEnumAttribute soapEnum = new SoapEnumAttribute("West");
// Override the "A" enumerator.
SoapAtts.SoapEnum = soapEnum;
soapOver.Add(typeof(GroupType), "A", SoapAtts);
// Add another SoapEnumAttribute for the GroupType.B enumerator.
// Instead of //B// it will be "East".
SoapAtts= new SoapAttributes();
soapEnum = new SoapEnumAttribute();
soapEnum.Name = "East";
SoapAtts.SoapEnum = soapEnum;
soapOver.Add(typeof(GroupType), "B", SoapAtts);
// Create an XmlSerializer used for overriding.
XmlTypeMapping map =
new SoapReflectionImporter(soapOver).
ImportTypeMapping(typeof(Group));
XmlSerializer ser = new XmlSerializer(map);
Group myGroup = new Group();
myGroup.GroupName = ".NET";
myGroup.Grouptype = GroupType.B;
// Writing the file requires a TextWriter.
TextWriter writer = new StreamWriter(fileName);
ser.Serialize(writer, myGroup);
writer.Close();
}
}
Imports System.IO
Imports System.Xml
Imports System.Xml.Serialization
Public Class Group
Public GroupName As String
Public Grouptype As GroupType
End Class
Public enum GroupType
' Use the SoapEnumAttribute to instruct the XmlSerializer
' to generate Small and Large instead of A and B.
<SoapEnum("Small")> _
A
<SoapEnum("Large")> _
B
End enum
Public Class Run
Public Shared Sub Main()
Dim test As Run = new Run()
test.SerializeObject("SoapEnum.xml")
test.SerializeOverride("SoapOverride.xml")
Console.WriteLine("Fininished writing two files")
End Sub
Private Shared Sub SerializeObject(filename As string)
' Create an instance of the XmlSerializer Class.
Dim mapp As XmlTypeMapping = _
(New SoapReflectionImporter()).ImportTypeMapping(GetType(Group))
Dim mySerializer As XmlSerializer = New XmlSerializer(mapp)
' Writing the file requires a TextWriter.
Dim writer As TextWriter = New StreamWriter(filename)
' Create an instance of the Class that will be serialized.
Dim myGroup As Group = New Group()
' Set the object properties.
myGroup.GroupName = ".NET"
myGroup.Grouptype= GroupType.A
' Serialize the Class, and close the TextWriter.
mySerializer.Serialize(writer, myGroup)
writer.Close()
End Sub
Private Sub SerializeOverride(fileName As String)
Dim soapOver As SoapAttributeOverrides = new SoapAttributeOverrides()
Dim SoapAtts As SoapAttributes = new SoapAttributes()
' Add a SoapEnumAttribute for the GroupType.A enumerator. Instead
' of 'A' it will be "West".
Dim soapEnum As SoapEnumAttribute = new SoapEnumAttribute("West")
' Override the "A" enumerator.
SoapAtts.SoapEnum = soapEnum
soapOver.Add(GetType(GroupType), "A", SoapAtts)
' Add another SoapEnumAttribute for the GroupType.B enumerator.
' Instead of 'B' it will be "East".
SoapAtts= New SoapAttributes()
soapEnum = new SoapEnumAttribute()
soapEnum.Name = "East"
SoapAtts.SoapEnum = soapEnum
soapOver.Add(GetType(GroupType), "B", SoapAtts)
' Create an XmlSerializer used for overriding.
Dim map As XmlTypeMapping = New SoapReflectionImporter _
(soapOver).ImportTypeMapping(GetType(Group))
Dim ser As XmlSerializer = New XmlSerializer(map)
Dim myGroup As Group = New Group()
myGroup.GroupName = ".NET"
myGroup.Grouptype = GroupType.B
' Writing the file requires a TextWriter.
Dim writer As TextWriter = New StreamWriter(fileName)
ser.Serialize(writer, myGroup)
writer.Close
End Sub
End Class
Commenti
Utilizzare per eseguire l'override SoapEnumAttribute di un'enumerazione esistente. Creare un nuovo SoapEnumAttributeoggetto , impostarne le proprietà e assegnare l'oggetto alla SoapEnum proprietà di un oggetto SoapAttributes. Per ogni membro dell'enumerazione, è necessario crearne uno nuovo SoapAttributes e aggiungerlo a SoapAttributeOverrides. Per altri dettagli, vedere la panoramica della SoapAttributeOverrides classe.
Nota
È possibile usare la parola SoapEnum
nel codice anziché quella più lunga SoapEnumAttribute.
Si applica a
SoapEnumAttribute(String)
Inizializza una nuova istanza della classe SoapEnumAttribute usando il nome di elemento specificato.
public:
SoapEnumAttribute(System::String ^ name);
public SoapEnumAttribute (string name);
new System.Xml.Serialization.SoapEnumAttribute : string -> System.Xml.Serialization.SoapEnumAttribute
Public Sub New (name As String)
Parametri
- name
- String
Nome dell'elemento XML generato dall'elemento XmlSerializer.
Esempio
Nell'esempio seguente viene utilizzato per XmlSerializer serializzare una classe denominata Food
che include un'enumerazione denominata FoodType
. L'enumerazione FoodType
viene sottoposta a override creando un SoapEnumAttribute oggetto per ogni enumerazione e impostando la SoapEnum proprietà di un SoapAttributes oggetto su SoapEnumAttribute. L'oggetto SoapAttributes viene aggiunto a un SoapAttributeOverrides oggetto utilizzato per creare un oggetto XmlSerializer.
#using <System.Xml.dll>
#using <System.dll>
using namespace System;
using namespace System::IO;
using namespace System::Xml;
using namespace System::Xml::Serialization;
public enum class GroupType
{
// Use the SoapEnumAttribute to instruct the XmlSerializer
// to generate Small and Large instead of A and B.
[SoapEnum("Small")]
A,
[SoapEnum("Large")]
B
};
public ref class Group
{
public:
String^ GroupName;
GroupType Grouptype;
};
public ref class Run
{
public:
void SerializeObject( String^ filename )
{
// Create an instance of the XmlSerializer Class.
XmlTypeMapping^ mapp = (gcnew SoapReflectionImporter)->ImportTypeMapping( Group::typeid );
XmlSerializer^ mySerializer = gcnew XmlSerializer( mapp );
// Writing the file requires a TextWriter.
TextWriter^ writer = gcnew StreamWriter( filename );
// Create an instance of the Class that will be serialized.
Group^ myGroup = gcnew Group;
// Set the Object* properties.
myGroup->GroupName = ".NET";
myGroup->Grouptype = GroupType::A;
// Serialize the Class, and close the TextWriter.
mySerializer->Serialize( writer, myGroup );
writer->Close();
}
void SerializeOverride( String^ fileName )
{
SoapAttributeOverrides^ soapOver = gcnew SoapAttributeOverrides;
SoapAttributes^ SoapAtts = gcnew SoapAttributes;
// Add a SoapEnumAttribute for the GroupType::A enumerator.
// Instead of 'A' it will be S"West".
SoapEnumAttribute^ soapEnum = gcnew SoapEnumAttribute( "West" );
// Override the S"A" enumerator.
SoapAtts->GroupType::SoapEnum = soapEnum;
soapOver->Add( GroupType::typeid, "A", SoapAtts );
// Add another SoapEnumAttribute for the GroupType::B enumerator.
// Instead of //B// it will be S"East".
SoapAtts = gcnew SoapAttributes;
soapEnum = gcnew SoapEnumAttribute;
soapEnum->Name = "East";
SoapAtts->GroupType::SoapEnum = soapEnum;
soapOver->Add( GroupType::typeid, "B", SoapAtts );
// Create an XmlSerializer used for overriding.
XmlTypeMapping^ map = (gcnew SoapReflectionImporter( soapOver ))->ImportTypeMapping( Group::typeid );
XmlSerializer^ ser = gcnew XmlSerializer( map );
Group^ myGroup = gcnew Group;
myGroup->GroupName = ".NET";
myGroup->Grouptype = GroupType::B;
// Writing the file requires a TextWriter.
TextWriter^ writer = gcnew StreamWriter( fileName );
ser->Serialize( writer, myGroup );
writer->Close();
}
};
int main()
{
Run^ test = gcnew Run;
test->SerializeObject( "SoapEnum.xml" );
test->SerializeOverride( "SoapOverride.xml" );
Console::WriteLine( "Fininished writing two files" );
}
using System;
using System.IO;
using System.Xml;
using System.Xml.Serialization;
public class Group{
public string GroupName;
public GroupType Grouptype;
}
public enum GroupType{
// Use the SoapEnumAttribute to instruct the XmlSerializer
// to generate Small and Large instead of A and B.
[SoapEnum("Small")]
A,
[SoapEnum("Large")]
B
}
public class Run {
static void Main(){
Run test= new Run();
test.SerializeObject("SoapEnum.xml");
test.SerializeOverride("SoapOverride.xml");
Console.WriteLine("Fininished writing two files");
}
private void SerializeObject(string filename){
// Create an instance of the XmlSerializer Class.
XmlTypeMapping mapp =
(new SoapReflectionImporter()).ImportTypeMapping(typeof(Group));
XmlSerializer mySerializer = new XmlSerializer(mapp);
// Writing the file requires a TextWriter.
TextWriter writer = new StreamWriter(filename);
// Create an instance of the Class that will be serialized.
Group myGroup = new Group();
// Set the object properties.
myGroup.GroupName = ".NET";
myGroup.Grouptype= GroupType.A;
// Serialize the Class, and close the TextWriter.
mySerializer.Serialize(writer, myGroup);
writer.Close();
}
private void SerializeOverride(string fileName){
SoapAttributeOverrides soapOver = new SoapAttributeOverrides();
SoapAttributes SoapAtts = new SoapAttributes();
// Add a SoapEnumAttribute for the GroupType.A enumerator.
// Instead of 'A' it will be "West".
SoapEnumAttribute soapEnum = new SoapEnumAttribute("West");
// Override the "A" enumerator.
SoapAtts.SoapEnum = soapEnum;
soapOver.Add(typeof(GroupType), "A", SoapAtts);
// Add another SoapEnumAttribute for the GroupType.B enumerator.
// Instead of //B// it will be "East".
SoapAtts= new SoapAttributes();
soapEnum = new SoapEnumAttribute();
soapEnum.Name = "East";
SoapAtts.SoapEnum = soapEnum;
soapOver.Add(typeof(GroupType), "B", SoapAtts);
// Create an XmlSerializer used for overriding.
XmlTypeMapping map =
new SoapReflectionImporter(soapOver).
ImportTypeMapping(typeof(Group));
XmlSerializer ser = new XmlSerializer(map);
Group myGroup = new Group();
myGroup.GroupName = ".NET";
myGroup.Grouptype = GroupType.B;
// Writing the file requires a TextWriter.
TextWriter writer = new StreamWriter(fileName);
ser.Serialize(writer, myGroup);
writer.Close();
}
}
Imports System.IO
Imports System.Xml
Imports System.Xml.Serialization
Public Class Group
Public GroupName As String
Public Grouptype As GroupType
End Class
Public enum GroupType
' Use the SoapEnumAttribute to instruct the XmlSerializer
' to generate Small and Large instead of A and B.
<SoapEnum("Small")> _
A
<SoapEnum("Large")> _
B
End enum
Public Class Run
Public Shared Sub Main()
Dim test As Run = new Run()
test.SerializeObject("SoapEnum.xml")
test.SerializeOverride("SoapOverride.xml")
Console.WriteLine("Fininished writing two files")
End Sub
Private Shared Sub SerializeObject(filename As string)
' Create an instance of the XmlSerializer Class.
Dim mapp As XmlTypeMapping = _
(New SoapReflectionImporter()).ImportTypeMapping(GetType(Group))
Dim mySerializer As XmlSerializer = New XmlSerializer(mapp)
' Writing the file requires a TextWriter.
Dim writer As TextWriter = New StreamWriter(filename)
' Create an instance of the Class that will be serialized.
Dim myGroup As Group = New Group()
' Set the object properties.
myGroup.GroupName = ".NET"
myGroup.Grouptype= GroupType.A
' Serialize the Class, and close the TextWriter.
mySerializer.Serialize(writer, myGroup)
writer.Close()
End Sub
Private Sub SerializeOverride(fileName As String)
Dim soapOver As SoapAttributeOverrides = new SoapAttributeOverrides()
Dim SoapAtts As SoapAttributes = new SoapAttributes()
' Add a SoapEnumAttribute for the GroupType.A enumerator. Instead
' of 'A' it will be "West".
Dim soapEnum As SoapEnumAttribute = new SoapEnumAttribute("West")
' Override the "A" enumerator.
SoapAtts.SoapEnum = soapEnum
soapOver.Add(GetType(GroupType), "A", SoapAtts)
' Add another SoapEnumAttribute for the GroupType.B enumerator.
' Instead of 'B' it will be "East".
SoapAtts= New SoapAttributes()
soapEnum = new SoapEnumAttribute()
soapEnum.Name = "East"
SoapAtts.SoapEnum = soapEnum
soapOver.Add(GetType(GroupType), "B", SoapAtts)
' Create an XmlSerializer used for overriding.
Dim map As XmlTypeMapping = New SoapReflectionImporter _
(soapOver).ImportTypeMapping(GetType(Group))
Dim ser As XmlSerializer = New XmlSerializer(map)
Dim myGroup As Group = New Group()
myGroup.GroupName = ".NET"
myGroup.Grouptype = GroupType.B
' Writing the file requires a TextWriter.
Dim writer As TextWriter = New StreamWriter(fileName)
ser.Serialize(writer, myGroup)
writer.Close
End Sub
End Class
Commenti
Specificare quando Name si desidera che l'enumeratore XML generato sia diverso dall'enumeratore trovato nell'enumerazione .
Nota
È possibile usare la parola SoapEnum
nel codice anziché quella più lunga SoapEnumAttribute.