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

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

StateManagedCollection.CreateKnownType メソッド

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

派生クラスでオーバーライドされた場合、IStateManager を実装するクラスのインスタンスを作成します。作成されるオブジェクトの型は、GetKnownTypes メソッドから返されるコレクションの指定されたメンバに基づきます。

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

Protected Overridable Function
 CreateKnownType ( _
    index As Integer _
) As Object
protected virtual Object CreateKnownType (
    int index
)
protected:
virtual Object^ CreateKnownType (
    int index
)
protected Object CreateKnownType (
    int index
)
protected function CreateKnownType (
    index : int
) : Object

パラメータ

index

GetKnownTypes から返される、順番に並べられた型リストに含まれる作成対象の IStateManager の型のインデックス。

戻り値
指定された index に基づいた IStateManager の派生クラスのインスタンス。

解説解説

CreateKnownType メソッドは、StateManagedCollection.System.Web.UI.IStateManager.LoadViewState メソッド実装での StateManagedCollection コレクションによって内部的に呼び出されます。派生コレクションは、CreateKnownType メソッドをオーバーライドして、指定された index によって識別される IStateManager 型の既定のインスタンスを返します。このインデックスは、GetKnownTypes メソッドによって返される型の 1 つに対応付けられています。

使用例使用例

厳密に型指定された StateManagedCollection クラスが CreateKnownType メソッドを実装する方法を次のコード例に示します。CreateKnownType の CycleCollection 実装では、渡されるインデックスに基づいて、Bicycle オブジェクトまたは Tricycle オブジェクトのいずれかの既定のインスタンスが返されます。このコード例は、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 名前空間
GetKnownTypes



英和和英テキスト翻訳

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

辞書ショートカット

すべての辞書の索引

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

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

   

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



StateManagedCollection.CreateKnownType メソッドのページの著作権

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

©2026 GRAS Group, Inc.RSS