XmlElementAttributes 클래스

정의

XmlElementAttribute 에서 클래스를 직렬화하는 기본 방법을 재정의하는 데 사용하는 XmlSerializer 개체의 컬렉션을 나타냅니다.

public ref class XmlElementAttributes : System::Collections::IList
public ref class XmlElementAttributes : System::Collections::CollectionBase
public class XmlElementAttributes : System.Collections.IList
public class XmlElementAttributes : System.Collections.CollectionBase
type XmlElementAttributes = class
    interface ICollection
    interface IEnumerable
    interface IList
type XmlElementAttributes = class
    inherit CollectionBase
Public Class XmlElementAttributes
Implements IList
Public Class XmlElementAttributes
Inherits CollectionBase
상속
XmlElementAttributes
상속
XmlElementAttributes
구현

예제

다음 예제에서는 serialize 된 Transportation 라는 단일 필드를 포함 하는 클래스 Vehicles 를 반환 하는 ArrayList합니다. 이 예제에서는 먼저 배열에 삽입하는 개체 XmlSerializerXmlElementAttribute 형식을 Vehicles 지정하는 필드에 클래스의 두 인스턴스를 적용합니다. 그런 다음 두 개체를 만들어 XmlElementAttribute 속성에 적용된 특성의 동작을 재정의합니다 Vehicles . 재정의되는 두 개체가 컬렉션XmlAttributesXmlElementAttributes 추가됩니다. 마지막으로, 이 예제는 필드에 의해 반환 Vehicles 된 개체 형식에 ArrayList 새 개체 형식을 삽입할 수 있도록 XmlSerializer 하는 값을 추가 XmlAttributes XmlAttributeOverrides합니다.

#using <System.Xml.dll>
#using <System.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml::Serialization;
using namespace System::Collections;
using namespace System::Xml;

public ref class Car
{
public:
   String^ Name;
};

public ref class Plane
{
public:
   String^ Name;
};

public ref class Truck
{
public:
   String^ Name;
};

public ref class Train
{
public:
   String^ Name;
};

public ref class Transportation
{
public:

   // Override these two XmlElementAttributes.

   [XmlElement(Car::typeid),
   XmlElement(Plane::typeid)]
   ArrayList^ Vehicles;
};

XmlSerializer^ CreateOverrider()
{
   // Create XmlAtrributes and XmlAttributeOverrides instances. 
   XmlAttributes^ attrs = gcnew XmlAttributes;
   XmlAttributeOverrides^ xOver = gcnew XmlAttributeOverrides;

   /* Create an XmlElementAttributes object to override 
      one of the attributes applied to 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 it 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;
}

void SerializeObject( String^ filename )
{
   // Create an XmlSerializer instance.
   XmlSerializer^ xSer = CreateOverrider();

   // Create the object.
   Transportation^ myTransportation = gcnew Transportation;

   /* Create two new, overriding objects that can be
      inserted into the Vehicles array. */
   myTransportation->Vehicles = gcnew ArrayList;
   Truck^ myTruck = gcnew Truck;
   myTruck->Name = "MyTruck";
   Train^ myTrain = gcnew Train;
   myTrain->Name = "MyTrain";
   myTransportation->Vehicles->Add( myTruck );
   myTransportation->Vehicles->Add( myTrain );
   TextWriter^ writer = gcnew StreamWriter( filename );
   xSer->Serialize( writer, myTransportation );
}

int main()
{
   SerializeObject( "OverrideElement.xml" );
}
using System;
using System.IO;
using System.Xml.Serialization;
using System.Collections;
using System.Xml;

public class Transportation
{
   // Override these two XmlElementAttributes.
   [XmlElement(typeof(Car)),
   XmlElement(typeof(Plane))]
   public ArrayList Vehicles;
}

public class Car
{
   public string Name;
}

public class Plane
{
   public string Name;
}

public class Truck
{
   public string Name;
}

public class Train
{
   public string Name;
}

public class Test
{
   public static void Main()
   {
      Test t = new Test();
      t.SerializeObject("OverrideElement.xml");
   }

   public XmlSerializer CreateOverrider()
   {
      // Create XmlAtrributes and XmlAttributeOverrides instances.

      XmlAttributes attrs = new XmlAttributes();

      XmlAttributeOverrides xOver =
      new XmlAttributeOverrides();

      /* Create an XmlElementAttributes object to override
      one of the attributes applied to 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 it 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 void SerializeObject(string filename)
   {
      // Create an XmlSerializer instance.
      XmlSerializer xSer = CreateOverrider();

      // Create the object.
      Transportation myTransportation =
      new Transportation();

      /* Create two new, overriding objects that can be
      inserted into the Vehicles array. */
      myTransportation.Vehicles = new ArrayList();
      Truck myTruck = new Truck();
      myTruck.Name = "MyTruck";

      Train myTrain = new Train();
      myTrain.Name = "MyTrain";

      myTransportation.Vehicles.Add(myTruck);
      myTransportation.Vehicles.Add(myTrain);

      TextWriter writer = new StreamWriter(filename);
      xSer.Serialize(writer, myTransportation);
   }
}
Imports System.IO
Imports System.Xml.Serialization
Imports System.Collections
Imports System.Xml


Public Class Transportation
    ' Override these two XmlElementAttributes.
    <XmlElement(GetType(Car)), _
     XmlElement(GetType(Plane))> _
    Public Vehicles As ArrayList
End Class

Public Class Car
    Public Name As String
End Class

Public Class Plane
    Public Name As String
End Class

Public Class Truck
    Public Name As String
End Class

Public Class Train
    Public Name As String
End Class

Public Class Test
    
    Public Shared Sub Main()
        Dim t As New Test()
        t.SerializeObject("OverrideElement.xml")
    End Sub
    
    
    Public Function CreateOverrider() As XmlSerializer
        ' Create XmlAtrributes and XmlAttributeOverrides instances. 
        Dim attrs As New XmlAttributes()
        
        Dim xOver As New XmlAttributeOverrides()
        
        ' Create an XmlElementAttributes object to override
        ' one of the attributes applied to 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 it 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
    
    
    Public Sub SerializeObject(ByVal filename As String)
        ' Create an XmlSerializer instance.
        Dim xSer As XmlSerializer = CreateOverrider()
        
        ' Create the object.
        Dim myTransportation As New Transportation()
        
        ' Create two new, overriding objects that can be
        ' inserted into the Vehicles array. 
        myTransportation.Vehicles = New ArrayList()
        Dim myTruck As New Truck()
        myTruck.Name = "MyTruck"
        
        Dim myTrain As New Train()
        myTrain.Name = "MyTrain"
        
        myTransportation.Vehicles.Add(myTruck)
        myTransportation.Vehicles.Add(myTrain)
        
        Dim writer As New StreamWriter(filename)
        xSer.Serialize(writer, myTransportation)
    End Sub
End Class

설명

클래스 XmlElementAttributes 의 속성에서 XmlElements 반환됩니다 XmlAttributes . 클래스와 클래스를 XmlAttributeOverrides 사용하여 클래스를 XmlAttributes 직렬화하는 기본 방법을 재정의 XmlSerializer 할 수 있습니다.

생성자

XmlElementAttributes()

XmlElementAttributes 클래스의 새 인스턴스를 초기화합니다.

속성

Capacity

CollectionBase에 포함될 수 있는 요소의 수를 가져오거나 설정합니다.

(다음에서 상속됨 CollectionBase)
Count

ICollection에 포함된 요소 수를 가져옵니다.

Count

CollectionBase 인스턴스에 포함된 요소 수를 가져옵니다. 이 속성은 재정의할 수 없습니다.

(다음에서 상속됨 CollectionBase)
InnerList

ArrayList 인스턴스의 요소 목록을 포함하는 CollectionBase를 가져옵니다.

(다음에서 상속됨 CollectionBase)
Item[Int32]

지정한 인덱스에 있는 요소를 가져오거나 설정합니다.

List

IList 인스턴스의 요소 목록을 포함하는 CollectionBase를 가져옵니다.

(다음에서 상속됨 CollectionBase)

메서드

Add(XmlElementAttribute)

XmlElementAttribute을 컬렉션에 추가합니다.

Clear()

IList에서 항목을 모두 제거합니다.

Clear()

CollectionBase 인스턴스에서 개체를 모두 제거합니다. 이 메서드는 재정의할 수 없습니다.

(다음에서 상속됨 CollectionBase)
Contains(XmlElementAttribute)

지정한 개체가 컬렉션에 포함되는지 여부를 결정합니다.

CopyTo(XmlElementAttribute[], Int32)

XmlElementAttributes 또는 그 일부를 1차원 배열에 복사합니다.

Equals(Object)

지정된 개체가 현재 개체와 같은지 확인합니다.

(다음에서 상속됨 Object)
GetEnumerator()

컬렉션을 반복하는 열거자를 반환합니다.

GetEnumerator()

CollectionBase 인스턴스를 반복하는 열거자를 반환합니다.

(다음에서 상속됨 CollectionBase)
GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
IndexOf(XmlElementAttribute)

지정된 XmlElementAttribute의 인덱스를 가져옵니다.

Insert(Int32, XmlElementAttribute)

XmlElementAttribute를 컬렉션에 삽입합니다.

MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
OnClear()

CollectionBase 인스턴스의 콘텐츠를 지운 후에 추가로 사용자 지정 프로세스를 수행합니다.

(다음에서 상속됨 CollectionBase)
OnClearComplete()

CollectionBase 인스턴스의 내용을 지운 후에 추가로 사용자 지정 프로세스를 수행합니다.

(다음에서 상속됨 CollectionBase)
OnInsert(Int32, Object)

CollectionBase 인스턴스에 새 요소를 삽입하기 전에 추가로 사용자 지정 프로세스를 수행합니다.

(다음에서 상속됨 CollectionBase)
OnInsertComplete(Int32, Object)

CollectionBase 인스턴스에 새 요소를 삽입한 후에 추가로 사용자 지정 프로세스를 수행합니다.

(다음에서 상속됨 CollectionBase)
OnRemove(Int32, Object)

CollectionBase 인스턴스에서 요소를 제거할 때 추가로 사용자 지정 프로세스를 수행합니다.

(다음에서 상속됨 CollectionBase)
OnRemoveComplete(Int32, Object)

CollectionBase 인스턴스에서 요소를 제거한 후에 추가로 사용자 지정 프로세스를 수행합니다.

(다음에서 상속됨 CollectionBase)
OnSet(Int32, Object, Object)

CollectionBase 인스턴스에 값을 설정하기 전에 추가로 사용자 지정 프로세스를 수행합니다.

(다음에서 상속됨 CollectionBase)
OnSetComplete(Int32, Object, Object)

CollectionBase 인스턴스에 값을 설정한 후에 추가로 사용자 지정 프로세스를 수행합니다.

(다음에서 상속됨 CollectionBase)
OnValidate(Object)

값의 유효성을 검사할 때 추가로 사용자 지정 프로세스를 수행합니다.

(다음에서 상속됨 CollectionBase)
Remove(XmlElementAttribute)

컬렉션에서 지정한 개체를 제거합니다.

RemoveAt(Int32)

지정한 인덱스에서 IList 항목을 제거합니다.

RemoveAt(Int32)

CollectionBase 인스턴스의 지정한 인덱스에서 요소를 제거합니다. 이 메서드는 재정의할 수 없습니다.

(다음에서 상속됨 CollectionBase)
ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)

명시적 인터페이스 구현

ICollection.CopyTo(Array, Int32)

특정 ICollection 인덱스부터 시작하여 Array의 요소를 Array에 복사합니다.

ICollection.CopyTo(Array, Int32)

대상 배열의 지정된 인덱스에서 시작하여 전체 CollectionBase을 호환되는 1차원 Array에 복사합니다.

(다음에서 상속됨 CollectionBase)
ICollection.IsSynchronized

ICollection에 대한 액세스가 동기화되어 스레드로부터 안전하게 보호되는지를 나타내는 값을 가져옵니다.

ICollection.IsSynchronized

CollectionBase에 대한 액세스가 동기화되어 스레드로부터 안전하게 보호되는지를 나타내는 값을 가져옵니다.

(다음에서 상속됨 CollectionBase)
ICollection.SyncRoot

ICollection에 대한 액세스를 동기화하는 데 사용할 수 있는 개체를 가져옵니다.

ICollection.SyncRoot

CollectionBase에 대한 액세스를 동기화하는 데 사용할 수 있는 개체를 가져옵니다.

(다음에서 상속됨 CollectionBase)
IList.Add(Object)

IList에 항목을 추가합니다.

IList.Add(Object)

개체를 CollectionBase의 끝 부분에 추가합니다.

(다음에서 상속됨 CollectionBase)
IList.Contains(Object)

IList에 특정 값이 들어 있는지 여부를 확인합니다.

IList.Contains(Object)

CollectionBase에 특정 요소가 들어 있는지 여부를 확인합니다.

(다음에서 상속됨 CollectionBase)
IList.IndexOf(Object)

IList에서 특정 항목의 인덱스를 결정합니다.

IList.IndexOf(Object)

지정한 Object를 검색하고, 전체 CollectionBase 내에서 처음 나오는 0부터 시작하는 인덱스를 반환합니다.

(다음에서 상속됨 CollectionBase)
IList.Insert(Int32, Object)

항목을 IList의 지정된 인덱스에 삽입합니다.

IList.Insert(Int32, Object)

CollectionBase의 지정된 인덱스에 요소를 삽입합니다.

(다음에서 상속됨 CollectionBase)
IList.IsFixedSize

IList의 크기가 고정되어 있는지 여부를 나타내는 값을 가져옵니다.

IList.IsFixedSize

CollectionBase의 크기가 고정되어 있는지 여부를 나타내는 값을 가져옵니다.

(다음에서 상속됨 CollectionBase)
IList.IsReadOnly

IList가 읽기 전용인지 여부를 나타내는 값을 가져옵니다.

IList.IsReadOnly

CollectionBase가 읽기 전용인지 여부를 나타내는 값을 가져옵니다.

(다음에서 상속됨 CollectionBase)
IList.Item[Int32]

지정한 인덱스에 있는 요소를 가져오거나 설정합니다.

IList.Item[Int32]

지정한 인덱스에 있는 요소를 가져오거나 설정합니다.

(다음에서 상속됨 CollectionBase)
IList.Remove(Object)

IList에서 맨 처음 발견되는 특정 개체를 제거합니다.

IList.Remove(Object)

CollectionBase에서 맨 처음 발견되는 특정 개체를 제거합니다.

(다음에서 상속됨 CollectionBase)

확장 메서드

Cast<TResult>(IEnumerable)

IEnumerable의 요소를 지정된 형식으로 캐스팅합니다.

OfType<TResult>(IEnumerable)

지정된 형식에 따라 IEnumerable의 요소를 필터링합니다.

AsParallel(IEnumerable)

쿼리를 병렬화할 수 있도록 합니다.

AsQueryable(IEnumerable)

IEnumerableIQueryable로 변환합니다.

적용 대상

추가 정보