SerializationInfo.GetValue メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > SerializationInfo.GetValue メソッドの意味・解説 

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
)

パラメータ

name

取得する値に関連付けられた名前。

type

取得する値の Type格納された値がこの型に変換できない場合は、InvalidCastException がスローさます。

戻り値
name関連付けられた、指定した Typeオブジェクト

例外例外
例外種類条件

ArgumentNullException

name または typenull 参照 (Visual Basic では Nothing) です。

InvalidCastException

name関連付けられた値を type変換できません。

SerializationException

指定した名前の要素が、現在のインスタンス内に見つかりません。

解説解説

SerializationInfo格納されデータが、要求した型のデータ、またはその派生クラス1 つデータ場合は、その値が直接返されます。それ以外場合は、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
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
SerializationInfo クラス
SerializationInfo メンバ
System.Runtime.Serialization 名前空間



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

SerializationInfo.GetValue メソッドのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



SerializationInfo.GetValue メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS