SerializationInfo.GetValue(String, Type) 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
저장소에서 값을 검색합니다 SerializationInfo .
public:
System::Object ^ GetValue(System::String ^ name, Type ^ type);
public object GetValue(string name, Type type);
member this.GetValue : string * Type -> obj
Public Function GetValue (name As String, type As Type) As Object
매개 변수
- name
- String
검색할 값과 연결된 이름입니다.
- type
- Type
Type 검색할 값의 값입니다. 저장된 값을 이 형식으로 변환할 수 없으면 시스템에서 을 throw합니다 InvalidCastException.
반품
에 연결된 지정된 Type 개체입니다 name.
예외
name 또는 type .입니다 null.
연결된 name 값을 .로 변환 type할 수 없습니다.
지정된 이름의 요소를 현재 인스턴스에서 찾을 수 없습니다.
예제
다음 코드 예제에서는 메서드를 사용하는 방법을 보여 줍니다 GetValue .
// A serializable LinkedList example. For the full LinkedList implementation
// see the Serialization sample.
[Serializable()]
class LinkedList: ISerializable {
public static void Main() {}
Node m_head = null;
Node m_tail = null;
// Serializes the object.
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
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.
<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
설명
저장된 데이터가 요청된 SerializationInfo 형식(또는 파생 클래스 중 하나)인 경우 해당 값이 직접 반환됩니다. 그렇지 않으면 IFormatterConverter.Convert 해당 형식으로 변환하기 위해 호출됩니다.
메서드에서 반환된 GetValue 값은 항상 매개 변수에 지정된 type 형식으로 안전하게 캐스팅될 수 있습니다.