StateManagedCollection.CreateKnownType メソッド
アセンブリ: System.Web (system.web.dll 内)

Dim index As Integer Dim returnValue As Object returnValue = Me.CreateKnownType(index)
戻り値
指定された 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(); } }

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- StateManagedCollection.CreateKnownType メソッドのページへのリンク