SoapAttributeOverrides::Item Property (Type^, String^)
Gets the object associated with the specified (base class) type. The member parameter specifies the base class member that is overridden.
Assembly: System.Xml (in System.Xml.dll)
public: property SoapAttributes^ default[ Type^ type, String^ member ] { SoapAttributes^ get(Type^ type, String^ member); }
Parameters
- type
-
Type:
System::Type^
The base class Type that is associated with the collection of attributes you want to override.
- member
-
Type:
System::String^
The name of the overridden member that specifies the SoapAttributes to return.
Property Value
Type: System.Xml.Serialization::SoapAttributes^A SoapAttributes that represents the collection of overriding attributes.
Use this overload to return a SoapAttributes that contains attributes that override a SoapAttributeAttribute, SoapElementAttribute, SoapIgnoreAttribute, or SoapEnumAttribute. You can also return a SoapAttributes that contains the override of a default value that uses a DefaultValueAttribute.
If the SoapAttributes contains a SoapTypeAttribute, you must use the overload that specifies only the overridden type.
The following example creates a SoapAttributeOverrides used to override the serialization of an instance of the Group class. The example also uses the Item property to retrieve the SoapAttributes that is used to specify how the serialization is being overridden.
#using <System.Xml.dll> #using <System.dll> using namespace System; using namespace System::IO; using namespace System::Xml; using namespace System::Xml::Serialization; public ref class Group { public: // Override the serialization of this member. String^ GroupName; }; public ref class Run { 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 = gcnew StreamWriter( filename ); // Create an instance of the class that will be serialized. Group^ myGroup = gcnew Group; // Set the object properties. myGroup->GroupName = ".NET"; // Serialize the class, and close the TextWriter. overRideSerializer->Serialize( writer, myGroup ); writer->Close(); } private: XmlSerializer^ CreateOverrideSerializer() { SoapAttributeOverrides^ mySoapAttributeOverrides = gcnew SoapAttributeOverrides; SoapAttributes^ mySoapAttributes = gcnew SoapAttributes; SoapElementAttribute^ mySoapElement = gcnew SoapElementAttribute; mySoapElement->ElementName = "TeamName"; mySoapAttributes->SoapElement = mySoapElement; // Add the SoapAttributes to the // mySoapAttributeOverridesrides object. mySoapAttributeOverrides->Add( Group::typeid, "GroupName", mySoapAttributes ); // Get the SoapAttributes with the Item property. SoapAttributes^ thisSoapAtts = mySoapAttributeOverrides[Group::typeid, "GroupName"]; Console::WriteLine( "New serialized element name: {0}", thisSoapAtts->SoapElement->ElementName ); // 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->SerializeOverride( "GetSoapAttributes.xml" ); }
Available since 1.1