XmlElementAttributes.Add(XmlElementAttribute) Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Adds an XmlElementAttribute to the collection.
public:
int Add(System::Xml::Serialization::XmlElementAttribute ^ attribute);
public int Add (System.Xml.Serialization.XmlElementAttribute attribute);
public int Add (System.Xml.Serialization.XmlElementAttribute? attribute);
member this.Add : System.Xml.Serialization.XmlElementAttribute -> int
Public Function Add (attribute As XmlElementAttribute) As Integer
Parameters
- attribute
- XmlElementAttribute
The XmlElementAttribute to add.
Returns
The zero-based index of the newly added item.
Examples
The following example creates two XmlElementAttribute objects and calls the Add method to add them to an XmlElementAttributes. The example then adds the XmlElementAttributes to an XmlAttributeOverrides, which is used to create an XmlSerializer that can serialize an instance of the Transportation
class.
public:
XmlSerializer^ CreateOverrider()
{
// Create XmlAttributes and XmlAttributeOverrides instances.
XmlAttributes^ attrs = gcnew XmlAttributes;
XmlAttributeOverrides^ xOver =
gcnew XmlAttributeOverrides;
/* Create an XmlElementAttributes to override
the Vehicles property. */
XmlElementAttribute^ xElement1 =
gcnew XmlElementAttribute( Truck::typeid );
// Add the XmlElementAttribute to the collection.
attrs->XmlElements->Add( xElement1 );
/* Create a second XmlElementAttribute, and
add to the collection. */
XmlElementAttribute^ xElement2 =
gcnew XmlElementAttribute( Train::typeid );
attrs->XmlElements->Add( xElement2 );
/* Add the XmlAttributes to the XmlAttributeOverrides,
specifying the member to override. */
xOver->Add( Transportation::typeid, "Vehicles", attrs );
// Create the XmlSerializer, and return it.
XmlSerializer^ xSer = gcnew XmlSerializer(
Transportation::typeid,xOver );
return xSer;
}
public XmlSerializer CreateOverrider()
{
// Create XmlAttributes and XmlAttributeOverrides instances.
XmlAttributes attrs = new XmlAttributes();
XmlAttributeOverrides xOver =
new XmlAttributeOverrides();
/* Create an XmlElementAttributes to override
the Vehicles property. */
XmlElementAttribute xElement1 =
new XmlElementAttribute(typeof(Truck));
// Add the XmlElementAttribute to the collection.
attrs.XmlElements.Add(xElement1);
/* Create a second XmlElementAttribute, and
add to the collection. */
XmlElementAttribute xElement2 =
new XmlElementAttribute(typeof(Train));
attrs.XmlElements.Add(xElement2);
/* Add the XmlAttributes to the XmlAttributeOverrides,
specifying the member to override. */
xOver.Add(typeof(Transportation), "Vehicles", attrs);
// Create the XmlSerializer, and return it.
XmlSerializer xSer = new XmlSerializer
(typeof(Transportation), xOver);
return xSer;
}
Public Function CreateOverrider() As XmlSerializer
' Create XmlAttributes and XmlAttributeOverrides instances.
Dim attrs As New XmlAttributes()
Dim xOver As New XmlAttributeOverrides()
' Create an XmlElementAttributes to override
' the Vehicles property.
Dim xElement1 As New XmlElementAttribute(GetType(Truck))
' Add the XmlElementAttribute to the collection.
attrs.XmlElements.Add(xElement1)
' Create a second XmlElementAttribute, and
' add to the collection.
Dim xElement2 As New XmlElementAttribute(GetType(Train))
attrs.XmlElements.Add(xElement2)
' Add the XmlAttributes to the XmlAttributeOverrides,
' specifying the member to override.
xOver.Add(GetType(Transportation), "Vehicles", attrs)
' Create the XmlSerializer, and return it.
Dim xSer As New XmlSerializer(GetType(Transportation), xOver)
Return xSer
End Function
End Class
Applies to
GitHub에서 Microsoft와 공동 작업
이 콘텐츠의 원본은 GitHub에서 찾을 수 있으며, 여기서 문제와 끌어오기 요청을 만들고 검토할 수도 있습니다. 자세한 내용은 참여자 가이드를 참조하세요.
.NET