SoapAttributes.SoapDefaultValue プロパティ
アセンブリ: System.Xml (system.xml.dll 内)

Dim instance As SoapAttributes Dim value As Object value = instance.SoapDefaultValue instance.SoapDefaultValue = value
/** @property */ public Object get_SoapDefaultValue () /** @property */ public void set_SoapDefaultValue (Object value)
public function get SoapDefaultValue () : Object public function set SoapDefaultValue (value : Object)
XML 要素または XML 属性の既定値を表すオブジェクト。

メンバの既定値は、そのメンバに DefaultValueAttribute 属性を適用することによって設定できます。メンバがエンコード済みの SOAP メッセージとしてシリアル化される場合に、その既定値を変更するには、新しい DefaultValueAttribute を作成し、その Value プロパティを設定し、このオブジェクトを SoapDefaultValue プロパティに設定します。次に、この SoapAttributes を SoapAttributeOverrides に追加します。詳細については、SoapAttributeOverrides クラスの概要を参照してください。

GroupName という名前のフィールドが含まれている Group という名前のクラスをシリアル化する例を次に示します。既定値は、DefaultValueAttribute を使用して ".NET" に設定されています。フィールドを設定しないか、またはフィールドを ".NET" に設定することにより、その値はシリアル化されなくなります (既定値が判明するため)。さらに、この例では、CreateOverrideSerializer メソッドで既定値がオーバーライドされています。このメソッドは、SerializeOverride メソッドによって呼び出されます。この例は、SerializeOriginal メソッドおよび SerializeOverride メソッドの両方を呼び出し、GroupName フィールドに対して同じ値 (".NET") を設定しています。指定されているオーバーライドにより、この値は SerializeOverride メソッドが呼び出された場合にだけシリアル化されます。
Imports System Imports System.IO Imports System.Xml Imports System.Xml.Serialization Imports System.Xml.Schema Imports System.ComponentModel Public Class Group ' The default is set to .NET. <DefaultValue(".NET")> _ Public GroupName As String End Class Public Class Run Public Shared Sub Main() Dim test As Run = new Run() test.SerializeOriginal("SoapOriginal.xml") test.SerializeOverride _ ("mySoapAttributeOverridesideAttributes.xml") test.DeserializeOriginal("SoapOriginal.xml") test.DeserializeOverride _ ("mySoapAttributeOverridesideAttributes.xml") End Sub public Sub SerializeOriginal(filename As String) ' Create an instance of the XmlSerializer class. Dim mySerializer As XmlSerializer = _ new XmlSerializer(GetType(Group)) ' 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() ' Setting the GroupName to '.NET' is like not setting it at all ' because it is the default value. So no value will be ' serialized, and on deserialization it will appear as a blank. myGroup.GroupName = ".NET" ' Serialize the class, and close the TextWriter. mySerializer.Serialize(writer, myGroup) writer.Close() End Sub Public Sub SerializeOverride(filename As String) ' Create an instance of the XmlSerializer class ' that overrides the serialization. Dim overRideSerializer As XmlSerializer = CreateOverrideSerializer() ' 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() ' The override specifies that the default value is now ' 'Team1'. So setting the GroupName to '.NET' means ' the value will be serialized. myGroup.GroupName = ".NET" ' Serialize the class, and close the TextWriter. overRideSerializer.Serialize(writer, myGroup) writer.Close() End Sub Public Sub DeserializeOriginal(filename As String) ' Create an instance of the XmlSerializer class. Dim mySerializer As XmlSerializer = new XmlSerializer(GetType(Group)) ' Reading the file requires a TextReader. Dim reader As TextReader = new StreamReader(filename) ' Deserialize and cast the object. Dim myGroup As Group = CType(mySerializer.Deserialize(reader), Group) Console.WriteLine(myGroup.GroupName) Console.WriteLine() End Sub Public Sub DeserializeOverride(filename As String) ' Create an instance of the XmlSerializer class. Dim overRideSerializer As XmlSerializer = CreateOverrideSerializer() ' Reading the file requires a TextReader. Dim reader As TextReader = new StreamReader(filename) ' Deserialize and cast the object. Dim myGroup As Group = CType(overRideSerializer.Deserialize(reader), Group) Console.WriteLine(myGroup.GroupName) End Sub Private Function CreateOverrideSerializer() As XmlSerializer Dim mySoapAttributeOverrides As SoapAttributeOverrides = _ New SoapAttributeOverrides() Dim soapAtts As SoapAttributes = New SoapAttributes() ' Create a new DefaultValueAttribute object for the GroupName ' property. Dim newDefault As DefaultValueAttribute = _ new DefaultValueAttribute("Team1") soapAtts.SoapDefaultValue = newDefault mySoapAttributeOverrides.Add(GetType(Group), "GroupName", _ soapAtts) ' Create an XmlTypeMapping that is used to create an instance ' of the XmlSerializer. Then return the XmlSerializer object. Dim myMapping As XmlTypeMapping = _ (New SoapReflectionImporter( _ mySoapAttributeOverrides)).ImportTypeMapping(GetType(Group)) Dim ser As XmlSerializer = new XmlSerializer(myMapping) return ser End Function End Class
using System; using System.IO; using System.Xml; using System.Xml.Serialization; using System.Xml.Schema; using System.ComponentModel; public class Group { // The default is set to .NET. [DefaultValue(".NET")] public string GroupName; } public class Run { public static void Main() { Run test = new Run(); test.SerializeOriginal("SoapOriginal.xml"); test.SerializeOverride("mySoapAttributeOverridesideAttributes.xml"); test.DeserializeOriginal("SoapOriginal.xml"); test.DeserializeOverride("mySoapAttributeOverridesideAttributes.xml"); } public void SerializeOriginal(string filename) { // Create an instance of the XmlSerializer class. XmlSerializer mySerializer = new XmlSerializer(typeof(Group)); // 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(); // Setting the GroupName to '.NET' is like not setting it at all // because it is the default value. So no value will be // serialized, and on deserialization it will appear as a blank. myGroup.GroupName = ".NET"; // Serialize the class, and close the TextWriter. mySerializer.Serialize(writer, myGroup); writer.Close(); } public void SerializeOverride(string filename) { // Create an instance of the XmlSerializer class // that overrides the serialization. XmlSerializer overRideSerializer = CreateOverrideSerializer(); // 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(); // The override specifies that the default value is now // 'Team1'. So setting the GroupName to '.NET' means // the value will be serialized. myGroup.GroupName = ".NET"; // Serialize the class, and close the TextWriter. overRideSerializer.Serialize(writer, myGroup); writer.Close(); } public void DeserializeOriginal(string filename) { // Create an instance of the XmlSerializer class. XmlSerializer mySerializer= new XmlSerializer(typeof(Group)); // Reading the file requires a TextReader. TextReader reader = new StreamReader(filename); // Deserialize and cast the object. Group myGroup; myGroup = (Group) mySerializer.Deserialize(reader); Console.WriteLine(myGroup.GroupName); Console.WriteLine(); } public void DeserializeOverride(string filename) { // Create an instance of the XmlSerializer class. XmlSerializer overRideSerializer = CreateOverrideSerializer(); // Reading the file requires a TextReader. TextReader reader = new StreamReader(filename); // Deserialize and cast the object. Group myGroup; myGroup = (Group) overRideSerializer.Deserialize(reader); Console.WriteLine(myGroup.GroupName); } private XmlSerializer CreateOverrideSerializer() { SoapAttributeOverrides mySoapAttributeOverrides = new SoapAttributeOverrides(); SoapAttributes soapAtts = new SoapAttributes(); // Create a new DefaultValueAttribute object for the GroupName // property. DefaultValueAttribute newDefault = new DefaultValueAttribute("Team1"); soapAtts.SoapDefaultValue = newDefault; mySoapAttributeOverrides.Add(typeof(Group), "GroupName", soapAtts); // Create an XmlTypeMapping that is used to create an instance // of the XmlSerializer. Then return the XmlSerializer object. XmlTypeMapping myMapping = (new SoapReflectionImporter( mySoapAttributeOverrides)).ImportTypeMapping(typeof(Group)); XmlSerializer ser = new XmlSerializer(myMapping); return ser; } }
#using <System.dll> #using <System.Xml.dll> using namespace System; using namespace System::IO; using namespace System::Xml; using namespace System::Xml::Serialization; using namespace System::Xml::Schema; using namespace System::ComponentModel; public ref class Group { public: // The default is set to .NET. [DefaultValue(".NET")] String^ GroupName; }; public ref class Run { public: void SerializeOriginal( String^ filename ) { // Create an instance of the XmlSerializer class. XmlSerializer^ mySerializer = gcnew XmlSerializer( Group::typeid ); // 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; // Setting the GroupName to '.NET' is like not setting it at all // because it is the default value. So no value will be // serialized, and on deserialization it will appear as a blank. myGroup->GroupName = ".NET"; // Serialize the class, and close the TextWriter. mySerializer->Serialize( writer, myGroup ); writer->Close(); } void SerializeOverride( String^ filename ) { // Create an instance of the XmlSerializer class // that overrides the serialization. XmlSerializer^ overRideSerializer = CreateOverrideSerializer(); // 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; // The specifies that the default value is now // 'Team1'. So setting the GroupName to '.NET' means // the value will be serialized. myGroup->GroupName = ".NET"; // Serialize the class, and close the TextWriter. overRideSerializer->Serialize( writer, myGroup ); writer->Close(); } void DeserializeOriginal( String^ filename ) { // Create an instance of the XmlSerializer class. XmlSerializer^ mySerializer = gcnew XmlSerializer( Group::typeid ); // Reading the file requires a TextReader. TextReader^ reader = gcnew StreamReader( filename ); // Deserialize and cast the Object*. Group^ myGroup; myGroup = safe_cast<Group^>(mySerializer->Deserialize( reader )); Console::WriteLine( myGroup->GroupName ); Console::WriteLine(); } void DeserializeOverride( String^ filename ) { // Create an instance of the XmlSerializer class. XmlSerializer^ overRideSerializer = CreateOverrideSerializer(); // Reading the file requires a TextReader. TextReader^ reader = gcnew StreamReader( filename ); // Deserialize and cast the Object*. Group^ myGroup; myGroup = safe_cast<Group^>(overRideSerializer->Deserialize( reader )); Console::WriteLine( myGroup->GroupName ); } private: XmlSerializer^ CreateOverrideSerializer() { SoapAttributeOverrides^ mySoapAttributeOverrides = gcnew SoapAttributeOverrides; SoapAttributes^ soapAtts = gcnew SoapAttributes; // Create a new DefaultValueAttribute Object* for the GroupName // property. DefaultValueAttribute^ newDefault = gcnew DefaultValueAttribute( "Team1" ); soapAtts->SoapDefaultValue = newDefault; mySoapAttributeOverrides->Add( Group::typeid, "GroupName", soapAtts ); // Create an XmlTypeMapping that is used to create an instance // of the XmlSerializer. Then return the XmlSerializer Object*. XmlTypeMapping^ myMapping = (gcnew SoapReflectionImporter( mySoapAttributeOverrides ))->ImportTypeMapping( Group::typeid ); XmlSerializer^ ser = gcnew XmlSerializer( myMapping ); return ser; } }; int main() { Run^ test = gcnew Run; test->SerializeOriginal( "SoapOriginal.xml" ); test->SerializeOverride( "mySoapAttributeOverridesideAttributes.xml" ); test->DeserializeOriginal( "SoapOriginal.xml" ); test->DeserializeOverride( "mySoapAttributeOverridesideAttributes.xml" ); }
import System.*; import System.IO.*; import System.Xml.*; import System.Xml.Serialization.*; import System.Xml.Schema.*; import System.ComponentModel.*; public class Group { // The default is set to .NET. /** @attribute DefaultValue(".NET") */ public String groupName; } //Group public class Run { public static void main(String[] args) { Run test = new Run(); test.SerializeOriginal("SoapOriginal.xml"); test.SerializeOverride("mySoapAttributeOverridesideAttributes.xml"); test.DeserializeOriginal("SoapOriginal.xml"); test.DeserializeOverride("mySoapAttributeOverridesideAttributes.xml"); } //main public void SerializeOriginal(String fileName) { // Create an instance of the XmlSerializer class. XmlSerializer mySerializer = new XmlSerializer(Group.class.ToType()); // 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(); // Setting the groupName to '.NET' is like not setting it at all // because it is the default value. So no value will be // serialized, and on deserialization it will appear as a blank. myGroup.groupName = ".NET"; // Serialize the class, and close the TextWriter. mySerializer.Serialize(writer, myGroup); writer.Close(); } //SerializeOriginal public void SerializeOverride(String fileName) { // Create an instance of the XmlSerializer class // that overrides the serialization. XmlSerializer overRideSerializer = CreateOverrideSerializer(); // 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(); // The override specifies that the default value is now // 'Team1'. So setting the groupName to '.NET' means // the value will be serialized. myGroup.groupName = ".NET"; // Serialize the class, and close the TextWriter. overRideSerializer.Serialize(writer, myGroup); writer.Close(); } //SerializeOverride public void DeserializeOriginal(String fileName) { // Create an instance of the XmlSerializer class. XmlSerializer mySerializer = new XmlSerializer(Group.class.ToType()); // Reading the file requires a TextReader. TextReader reader = new StreamReader(fileName); // Deserialize and cast the object. Group myGroup; myGroup = ((Group)mySerializer.Deserialize(reader)); Console.WriteLine(myGroup.groupName); Console.WriteLine(); } //DeserializeOriginal public void DeserializeOverride(String fileName) { // Create an instance of the XmlSerializer class. XmlSerializer overRideSerializer = CreateOverrideSerializer(); // Reading the file requires a TextReader. TextReader reader = new StreamReader(fileName); // Deserialize and cast the object. Group myGroup; myGroup = (Group)(overRideSerializer.Deserialize(reader)); Console.WriteLine(myGroup.groupName); } //DeserializeOverride private XmlSerializer CreateOverrideSerializer() { SoapAttributeOverrides mySoapAttributeOverrides = new SoapAttributeOverrides(); SoapAttributes soapAtts = new SoapAttributes(); // Create a new DefaultValueAttribute object for the groupName // property. DefaultValueAttribute newDefault = new DefaultValueAttribute("Team1"); soapAtts.set_SoapDefaultValue(newDefault); mySoapAttributeOverrides.Add(Group.class.ToType(), "groupName", soapAtts); // Create an XmlTypeMapping that is used to create an instance // of the XmlSerializer. Then return the XmlSerializer object. XmlTypeMapping myMapping = (new SoapReflectionImporter( mySoapAttributeOverrides)).ImportTypeMapping(Group.class.ToType()); XmlSerializer ser = new XmlSerializer(myMapping); return ser; } //CreateOverrideSerializer } //Run

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からSoapAttributes.SoapDefaultValue プロパティを検索する場合は、下記のリンクをクリックしてください。

- SoapAttributes.SoapDefaultValue プロパティのページへのリンク