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

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

StateManagedCollection.GetKnownTypes メソッド

メモ : このメソッドは、.NET Framework version 2.0新しく追加されたものです。

派生クラスオーバーライドされた場合、StateManagedCollection コレクション格納できる IStateManager 型の配列取得します

名前空間: System.Web.UI
アセンブリ: System.Web (system.web.dll 内)
構文構文

解説解説

GetKnownTypes メソッドは、System.Web.UI.IStateManager.SaveViewState メソッド実装での StateManagedCollection コレクションによって内部的に呼び出されます。派生コレクションは、GetKnownTypes メソッドオーバーライドして、コレクション格納できる型を表す Type オブジェクト配列返します

使用例使用例

厳密に指定されStateManagedCollection クラスGetKnownTypes メソッド実装する方法次のコード例示しますGetKnownTypesCycleCollection 実装は、Bicycle 型と Tricycle 型が含まれる既知の型の Type 配列返します。このコード例は、StateManagedCollection クラストピック取り上げているコード例一部分です。

'////////////////////////////////////////////////////////////
'
' The strongly typed CycleCollection class is a collection
' that contains Cycle class instances, which implement the
' IStateManager interface.
'
'////////////////////////////////////////////////////////////
<AspNetHostingPermission(SecurityAction.Demand, _
    Level:=AspNetHostingPermissionLevel.Minimal)> _
               Public NotInheritable Class
 CycleCollection
    Inherits StateManagedCollection

    Private Shared _typesOfCycles() As
 Type = _
        {GetType(Bicycle), GetType(Tricycle)}

    Protected Overrides Function
 CreateKnownType(ByVal index As Integer)
 As Object
        Select Case index
            Case 0
                Return New Bicycle()
            Case 1
                Return New Tricycle()
            Case Else
                Throw New ArgumentOutOfRangeException("Unknown
 Type")
        End Select

    End Function


    Protected Overrides Function
 GetKnownTypes() As Type()
        Return _typesOfCycles

    End Function


    Protected Overrides Sub
 SetDirtyObject(ByVal o As Object)
        CType(o, Cycle).SetDirty()

    End Sub
End Class
//////////////////////////////////////////////////////////////
//
// The strongly typed CycleCollection class is a collection
// that contains Cycle class instances, which implement the
// IStateManager interface.
//
//////////////////////////////////////////////////////////////
[AspNetHostingPermission(SecurityAction.Demand, 
    Level=AspNetHostingPermissionLevel.Minimal)]
public sealed class CycleCollection : StateManagedCollection
 {
    
    private static readonly Type[] _typesOfCycles
 
        = new Type[] { typeof(Bicycle), typeof(Tricycle) };

    protected override object CreateKnownType(int
 index) {
        switch(index) {
            case 0:
                return new Bicycle();
            case 1:
                return new Tricycle();    
                
            default:
                throw new ArgumentOutOfRangeException("Unknown
 Type");
        }            
    }

    protected override Type[] GetKnownTypes() {
        return _typesOfCycles;
    }

    protected override void SetDirtyObject(object
 o) {
        ((Cycle)o).SetDirty();
    }

}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
StateManagedCollection クラス
StateManagedCollection メンバ
System.Web.UI 名前空間
CreateKnownType


このページでは「.NET Framework クラス ライブラリ リファレンス」からStateManagedCollection.GetKnownTypes メソッドを検索した結果を表示しています。
Weblioに収録されているすべての辞書からStateManagedCollection.GetKnownTypes メソッドを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からStateManagedCollection.GetKnownTypes メソッド を検索

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

辞書ショートカット

すべての辞書の索引

「StateManagedCollection.GetKnownTypes メソッド」の関連用語

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

   

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



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

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

©2025 GRAS Group, Inc.RSS