XmlElementAttributes.Add(XmlElementAttribute) 메서드

정의

컬렉션에 추가 XmlElementAttribute 합니다.

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

매개 변수

attribute
XmlElementAttribute

추가할 개체입니다 XmlElementAttribute .

반품

새로 추가된 항목의 인덱스(0부터 시작하는 인덱스)입니다.

예제

다음 예제에서는 두 개체 XmlElementAttribute 를 만들고 메서드를 Add 호출하여 개체를 추가합니다 XmlElementAttributes. 그런 다음 클래스의 XmlElementAttributes 인스턴스를 XmlAttributeOverridesserialize할 수 있는 클래스를 XmlSerializer 만드는 데 사용되는 에 추가합니다 Transportation .

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

적용 대상