SerializationInfo.GetValue 메서드
SerializationInfo 저장소에서 값을 검색합니다.
네임스페이스: System.Runtime.Serialization
어셈블리: mscorlib(mscorlib.dll)
구문
‘선언
Public Function GetValue ( _
name As String, _
type As Type _
) As Object
‘사용 방법
Dim instance As SerializationInfo
Dim name As String
Dim type As Type
Dim returnValue As Object
returnValue = instance.GetValue(name, type)
public Object GetValue (
string name,
Type type
)
public:
Object^ GetValue (
String^ name,
Type^ type
)
public Object GetValue (
String name,
Type type
)
public function GetValue (
name : String,
type : Type
) : Object
매개 변수
- name
검색할 값과 관련된 이름입니다.
- type
검색할 값의 Type입니다. 저장된 값을 이 형식으로 변환할 수 없는 경우 시스템은 InvalidCastException을 throw합니다.
반환 값
name과 관련된 지정된 Type의 개체입니다.
예외
예외 형식 | 조건 |
---|---|
name 또는 type이 Null 참조(Visual Basic의 경우 Nothing)인 경우 |
|
InvalidCastException |
name과 관련된 값을 type으로 변환할 수 없는 경우 |
지정된 이름을 가진 요소가 현재 인스턴스에 없는 경우 |
설명
SerializationInfo에 저장된 데이터가 요청된 형식의 데이터이거나 파생 클래스 중 하나이면 해당 값이 즉시 반환되고, 그렇지 않으면 IFormatterConverter.Convert가 호출되어 이 형식을 적절한 형식으로 변환합니다.
GetValue 메서드에 의해 반환되는 값은 항상 type 매개 변수에 지정된 형식으로 안전하게 캐스팅할 수 있습니다.
예제
다음 코드 예제는 GetValue 메서드의 사용에 대해 설명합니다.
' A serializable LinkedList example. For the full LinkedList implementation
' see the Serialization sample in the .NET Framework SDK.
<Serializable()> Class LinkedList
Implements ISerializable
Public Shared Sub Main()
End Sub
Private m_head As Node = Nothing
Private m_tail As Node = Nothing
' Serializes the object.
Public Sub GetObjectData(info As SerializationInfo, _
context As StreamingContext) Implements ISerializable.GetObjectData
' Stores the m_head and m_tail references in the SerializationInfo info.
info.AddValue("head", m_head, m_head.GetType())
info.AddValue("tail", m_tail, m_tail.GetType())
End Sub
' Constructor that is called automatically during deserialization.
' Reconstructs the object from the information in SerializationInfo info.
Private Sub New(info As SerializationInfo, context As StreamingContext)
Dim temp As New Node(0)
' Retrieves the values of Type temp.GetType() from SerializationInfo info.
m_head = CType(info.GetValue("head", temp.GetType()), Node)
m_tail = CType(info.GetValue("tail", temp.GetType()), Node)
End Sub
End Class
// A serializable LinkedList example. For the full LinkedList implementation
// see the Serialization sample in the .NET Framework SDK.
[Serializable()]
class LinkedList: ISerializable {
public static void Main() {}
Node m_head = null;
Node m_tail = null;
// Serializes the object.
[SecurityPermissionAttribute(SecurityAction.Demand, SerializationFormatter=true)]
public void GetObjectData(SerializationInfo info, StreamingContext context){
// Stores the m_head and m_tail references in the SerializationInfo info.
info.AddValue("head", m_head, m_head.GetType());
info.AddValue("tail", m_tail, m_tail.GetType());
}
// Constructor that is called automatically during deserialization.
// Reconstructs the object from the information in SerializationInfo info
[SecurityPermissionAttribute(SecurityAction.Demand, SerializationFormatter=true)]
private LinkedList(SerializationInfo info, StreamingContext context)
{
Node temp = new Node(0);
// Retrieves the values of Type temp.GetType() from SerializationInfo info
m_head = (Node)info.GetValue("head", temp.GetType());
m_tail = (Node)info.GetValue("tail", temp.GetType());
}
}
// A serializable LinkedList example. For the full LinkedList implementation
// see the Serialization sample in the .NET Framework SDK.
[Serializable]
ref class LinkedList: public ISerializable
{
private:
Node^ m_head;
Node^ m_tail;
// Serializes the object.
public:
virtual void GetObjectData( SerializationInfo^ info, StreamingContext /*context*/ )
{
// Stores the m_head and m_tail references in the SerializationInfo info.
info->AddValue( "head", m_head, m_head->GetType() );
info->AddValue( "tail", m_tail, m_tail->GetType() );
}
// Constructor that is called automatically during deserialization.
private:
// Reconstructs the object from the information in SerializationInfo info
LinkedList( SerializationInfo^ info, StreamingContext /*context*/ )
{
Node^ temp = gcnew Node( 0 );
// Retrieves the values of Type temp.GetType() from SerializationInfo info
m_head = dynamic_cast<Node^>(info->GetValue( "head", temp->GetType() ));
m_tail = dynamic_cast<Node^>(info->GetValue( "tail", temp->GetType() ));
}
};
// A serializable LinkedList example. For the full LinkedList implementation
// see the Serialization sample in the.NET Framework SDK.
/** @attribute Serializable()
*/
class LinkedList implements ISerializable
{
public static void main(String[] args)
{
} //main
private Node m_head = null;
private Node m_tail = null;
// Serializes the object.
/** @attribute SecurityPermissionAttribute(SecurityAction.Demand, SerializationFormatter=true)
*/
public void GetObjectData(SerializationInfo info, StreamingContext context)
{
// Stores the m_head and m_tail references in the SerializationInfo
// info.
info.AddValue("head", m_head, m_head.GetType());
info.AddValue("tail", m_tail, m_tail.GetType());
} // GetObjectData
// Constructor that is called automatically during deserialization.
// Reconstructs the object from the information in SerializationInfo info
/** @attribute SecurityPermissionAttribute(SecurityAction.Demand, SerializationFormatter=true)
*/
private LinkedList(SerializationInfo info, StreamingContext context)
{
Node temp = new Node(0);
// Retrieves the values of Type temp.GetType() from SerializationInfo
// info
m_head = ((Node)(info.GetValue("head", temp.GetType())));
m_tail = ((Node)(info.GetValue("tail", temp.GetType())));
} //LinkedList
} //LinkedList
플랫폼
Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
.NET Framework에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.
버전 정보
.NET Framework
2.0, 1.1, 1.0에서 지원
참고 항목
참조
SerializationInfo 클래스
SerializationInfo 멤버
System.Runtime.Serialization 네임스페이스