XmlElementAttributes 클래스
정의
XmlElementAttribute가 클래스를 serialize하는 기본 방식을 재정의하는 데 사용하는 XmlSerializer 개체의 컬렉션을 나타냅니다.Represents a collection of XmlElementAttribute objects used by the XmlSerializer to override the default way it serializes a class.
public ref class XmlElementAttributes : System::Collections::CollectionBase
public class XmlElementAttributes : System.Collections.CollectionBase
type XmlElementAttributes = class
inherit CollectionBase
Public Class XmlElementAttributes
Inherits CollectionBase
- 상속
예제
다음 예제에서는 serialize 된 Transportation
라는 단일 필드를 포함 하는 클래스 Vehicles
를 반환 하는 ArrayList합니다.The following example serializes the Transportation
class, which contains a single field named Vehicles
that returns an ArrayList. 두 인스턴스를 먼저 적용 하는 예제를 XmlElementAttribute 클래스를 Vehicles
개체의 형식을 지정 하는 필드를 XmlSerializer 을 배열에 삽입 합니다.The example first applies two instances of the XmlElementAttribute class to the Vehicles
field that specifies the types of objects the XmlSerializer inserts into the array. 이 예에서는 다음 두 만듭니다 XmlElementAttribute 적용 된 특성의 동작을 재정의 하는 개체는 Vehicles
속성입니다.The example then creates two XmlElementAttribute objects to override the behavior of the attributes applied to the Vehicles
property. 재정의 두 개체에 추가 됩니다는 XmlElementAttributes 의 컬렉션을 XmlAttributes입니다.The two overriding objects are added to the XmlElementAttributes collection of an XmlAttributes. 마지막으로,이 예제에서는 추가 합니다 XmlAttributes 에 XmlAttributeOverrides허용를 XmlSerializer 에 새 개체 형식에 삽입할를 ArrayList 반환한를 Vehicles
필드.Lastly, the example adds the XmlAttributes to an XmlAttributeOverrides, allowing the XmlSerializer to insert the new object types into the ArrayList returned by the Vehicles
field.
#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 클래스.The XmlElementAttributes is returned by the XmlElements property of the XmlAttributes class. 사용 하 여 합니다 XmlAttributeOverrides 클래스 및 XmlAttributes 클래스 기본값을 재정의할 수 방식으로 XmlSerializer 클래스를 serialize 합니다.By using the XmlAttributeOverrides class and the XmlAttributes class, you can override the default way that the XmlSerializer serializes a class.
생성자
XmlElementAttributes() |
XmlElementAttributes 클래스의 새 인스턴스를 초기화합니다.Initializes a new instance of the XmlElementAttributes class. |
속성
Capacity |
CollectionBase에 포함될 수 있는 요소의 수를 가져오거나 설정합니다.Gets or sets the number of elements that the CollectionBase can contain. (다음에서 상속됨 CollectionBase) |
Count | |
InnerList |
가져옵니다는 ArrayList 의 요소 목록을 포함 하는 CollectionBase 인스턴스.Gets an ArrayList containing the list of elements in the CollectionBase instance. (다음에서 상속됨 CollectionBase) |
Item[Int32] |
지정한 인덱스에 있는 요소를 가져오거나 설정합니다.Gets or sets the element at the specified index. |
List |
가져옵니다는 IList 의 요소 목록을 포함 하는 CollectionBase 인스턴스.Gets an IList containing the list of elements in the CollectionBase instance. (다음에서 상속됨 CollectionBase) |
메서드
Add(XmlElementAttribute) |
XmlElementAttribute를 컬렉션에 추가합니다.Adds an XmlElementAttribute to the collection. |
Clear() | |
Contains(XmlElementAttribute) |
컬렉션에 지정된 개체가 들어 있는지 여부를 확인합니다.Determines whether the collection contains the specified object. |
CopyTo(XmlElementAttribute[], Int32) |
XmlElementAttributes 또는 그 일부를 1차원 배열에 복사합니다.Copies the XmlElementAttributes, or a portion of it to a one-dimensional array. |
Equals(Object) |
지정한 개체와 현재 개체가 같은지 여부를 확인합니다.Determines whether the specified object is equal to the current object. (다음에서 상속됨 Object) |
GetEnumerator() | |
GetHashCode() |
기본 해시 함수로 작동합니다.Serves as the default hash function. (다음에서 상속됨 Object) |
GetType() |
현재 인스턴스의 Type을 가져옵니다.Gets the Type of the current instance. (다음에서 상속됨 Object) |
IndexOf(XmlElementAttribute) |
지정된 XmlElementAttribute의 인덱스를 가져옵니다.Gets the index of the specified XmlElementAttribute. |
Insert(Int32, XmlElementAttribute) |
XmlElementAttribute를 컬렉션에 삽입합니다.Inserts an XmlElementAttribute into the collection. |
MemberwiseClone() |
현재 Object의 단순 복사본을 만듭니다.Creates a shallow copy of the current Object. (다음에서 상속됨 Object) |
OnClear() |
CollectionBase 인스턴스의 콘텐츠를 지운 후에 추가로 사용자 지정 프로세스를 수행합니다.Performs additional custom processes when clearing the contents of the CollectionBase instance. (다음에서 상속됨 CollectionBase) |
OnClearComplete() |
내용을 지운 후 사용자 지정 프로세스를 추가로 수행 합니다 CollectionBase 인스턴스.Performs additional custom processes after clearing the contents of the CollectionBase instance. (다음에서 상속됨 CollectionBase) |
OnInsert(Int32, Object) |
새 요소를 삽입 하기 전에 추가로 사용자 지정 프로세스를 수행 합니다 CollectionBase 인스턴스.Performs additional custom processes before inserting a new element into the CollectionBase instance. (다음에서 상속됨 CollectionBase) |
OnInsertComplete(Int32, Object) |
새 요소를 삽입 한 후 추가 사용자 지정 프로세스를 수행 합니다 CollectionBase 인스턴스.Performs additional custom processes after inserting a new element into the CollectionBase instance. (다음에서 상속됨 CollectionBase) |
OnRemove(Int32, Object) |
요소를 제거 하는 경우 추가 사용자 지정 프로세스를 수행 합니다 CollectionBase 인스턴스.Performs additional custom processes when removing an element from the CollectionBase instance. (다음에서 상속됨 CollectionBase) |
OnRemoveComplete(Int32, Object) |
요소를 제거한 후 추가 사용자 지정 프로세스를 수행 합니다 CollectionBase 인스턴스.Performs additional custom processes after removing an element from the CollectionBase instance. (다음에서 상속됨 CollectionBase) |
OnSet(Int32, Object, Object) |
에 값을 설정 하기 전에 추가로 사용자 지정 프로세스를 수행 합니다 CollectionBase 인스턴스.Performs additional custom processes before setting a value in the CollectionBase instance. (다음에서 상속됨 CollectionBase) |
OnSetComplete(Int32, Object, Object) |
값을 설정한 후 추가 사용자 지정 프로세스를 수행 합니다 CollectionBase 인스턴스.Performs additional custom processes after setting a value in the CollectionBase instance. (다음에서 상속됨 CollectionBase) |
OnValidate(Object) |
값 유효성을 검사할 때 추가로 사용자 지정 프로세스를 수행 합니다.Performs additional custom processes when validating a value. (다음에서 상속됨 CollectionBase) |
Remove(XmlElementAttribute) |
컬렉션에서 지정된 개체를 제거합니다.Removes the specified object from the collection. |
RemoveAt(Int32) | |
ToString() |
현재 개체를 나타내는 문자열을 반환합니다.Returns a string that represents the current object. (다음에서 상속됨 Object) |
명시적 인터페이스 구현
확장 메서드
Cast<TResult>(IEnumerable) |
IEnumerable의 요소를 지정된 형식으로 캐스팅합니다.Casts the elements of an IEnumerable to the specified type. |
OfType<TResult>(IEnumerable) |
지정된 형식에 따라 IEnumerable의 요소를 필터링합니다.Filters the elements of an IEnumerable based on a specified type. |
AsParallel(IEnumerable) |
쿼리를 병렬화할 수 있도록 합니다.Enables parallelization of a query. |
AsQueryable(IEnumerable) |
IEnumerable을 IQueryable로 변환합니다.Converts an IEnumerable to an IQueryable. |
적용 대상
추가 정보
- XmlAttributes
- XML Serialization 소개Introducing XML Serialization
- 방법: XML 스트림의 대체 요소 이름 지정How to: Specify an Alternate Element Name for an XML Stream
- 특성을 사용하여 XML Serialization 제어Controlling XML Serialization Using Attributes
- XML Serialization 예제Examples of XML Serialization
- XML Schema Definition Tool (Xsd.exe)XML Schema Definition Tool (Xsd.exe)