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 メソッド実装する方法次のコード例示しますCreateKnownTypeCycleCollection 実装では、渡されるインデックス基づいて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



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

辞書ショートカット

すべての辞書の索引

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

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

   

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



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

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

©2025 GRAS Group, Inc.RSS