StateManagedCollection.CreateKnownType(Int32) 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
파생 클래스에서 재정의되는 경우 구현하는 클래스의 인스턴스를 만듭니다 IStateManager. 만든 개체의 형식은 메서드에서 반환된 컬렉션의 지정된 멤버를 기반으로 합니다 GetKnownTypes() .
protected:
virtual System::Object ^ CreateKnownType(int index);
protected virtual object CreateKnownType(int index);
abstract member CreateKnownType : int -> obj
override this.CreateKnownType : int -> obj
Protected Overridable Function CreateKnownType (index As Integer) As Object
매개 변수
- index
- Int32
만들 형식의 순서가 지정된 형식 GetKnownTypes()목록의 IStateManager 인덱스입니다.
반품
제공된 항목에 따라 파생된 IStateManager클래스의 index 인스턴스입니다.
예외
파생 클래스에서 재정의되지 않은 경우 모든 경우에.
예제
다음 코드 예제에서는 강력한 형식 StateManagedCollection 의 클래스 메서드를 구현 하는 방법을 보여 줍니다 CreateKnownType . 구현 CycleCollection 은 CreateKnownType 전달된 인덱스 여부에 따라 개체 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 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();
}
}
'////////////////////////////////////////////////////////////
'
' 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
설명
메서드는 CreateKnownType 메서드의 구현에서 StateManagedCollection 컬렉션에 의해 내부적으로 호출됩니다 StateManagedCollection.IStateManager.LoadViewState . 파생 컬렉션은 제공CreateKnownType된 형식으로 식별되는 형식의 기본 인스턴스를 반환하도록 메서드를 재정 IStateManager 의 index 합니다. 이 인스턴스는 메서드에서 반환된 GetKnownTypes 형식 중 하나에 매핑됩니다.