Per Mausklick bewerten und Feedback geben
MSDN
MSDN Library
.NET Entwicklung
.NET Framework 3.5
.NET Framework
 GetValue-Methode
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework-Klassenbibliothek
SerializationInfo..::.GetValue-Methode

Ruft einen Wert aus dem SerializationInfo-Speicher ab.

Namespace:  System.Runtime.Serialization
Assembly:  mscorlib (in mscorlib.dll)

Visual Basic (Deklaration)
Public Function GetValue ( _
    name As String, _
    type As Type _
) As Object
Visual Basic (Verwendung)
Dim instance As SerializationInfo
Dim name As String
Dim type As Type
Dim returnValue As Object

returnValue = instance.GetValue(name, _
    type)
C#
public Object GetValue(
    string name,
    Type type
)
VisualC++
public:
Object^ GetValue(
    String^ name, 
    Type^ type
)
J#
public Object GetValue(
    String name,
    Type type
)
Jscript
public function GetValue(
    name : String, 
    type : Type
) : Object

Parameter

name
Typ: System..::.String

Der dem abzurufenden Wert zugeordnete Name.

type
Typ: System..::.Type

Der Type des abzurufenden Werts. Wenn der gespeicherte Wert nicht in diesen Typ konvertiert werden kann, löst das System eine InvalidCastException aus.

Rückgabewert

Typ: System..::.Object

Das Objekt vom angegebenen Type, dem der name zugeordnet ist.

AusnahmeBedingung
ArgumentNullException

Der name oder der type ist nullNothingnullptrNULL-Verweis (Nothing in Visual Basic).

InvalidCastException

Der Wert, dem der name zugeordnet ist, kann nicht in den type konvertiert werden.

SerializationException

In der aktuellen Instanz wurde kein Element mit dem angegebenen Namen gefunden.

Wenn die in der SerializationInfo gespeicherten Daten dem angeforderten Typ oder einer seiner abgeleiteten Klassen entsprechen, wird dieser Wert direkt zurückgegeben. Andernfalls wird IFormatterConverter..::.Convert aufgerufen, um den Wert in den entsprechenden Typ zu konvertieren.

Der von der GetValue-Methode zurückgegebene Wert kann stets problemlos in den im type-Parameter angegebenen Typ umgewandelt werden.

Im folgenden Codebeispiel wird die Verwendung der GetValue-Methode veranschaulicht.

Visual Basic
' 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

C#
// 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.
   [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());
   }
}

VisualC++
// A serializable LinkedList example.  For the full LinkedList implementation
// see the Serialization sample.
[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() ));
   }
};

J#
// A serializable LinkedList example.  For the full LinkedList implementation
// see the Serialization sample.

/** @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 Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

.NET Framework und .NET Compact Framework unterstützen nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen für .NET Framework.

.NET Framework

Unterstützt in: 3.5, 3.0 SP1, 3.0, 2.0 SP1, 2.0, 1.1, 1.0
Community Content   Was ist Community Content?
Neuen Inhalt hinzufügen RSS  Anmerkungen
Processing
Page view tracker