StateManagedCollection.GetKnownTypes 메서드

정의

파생 클래스에서 재정의된 경우 StateManagedCollection 컬렉션에 포함할 수 있는 IStateManager 형식의 배열을 가져옵니다.

protected:
 virtual cli::array <Type ^> ^ GetKnownTypes();
protected virtual Type[] GetKnownTypes ();
abstract member GetKnownTypes : unit -> Type[]
override this.GetKnownTypes : unit -> Type[]
Protected Overridable Function GetKnownTypes () As Type()

반환

Type[]

컬렉션에 포함할 수 있는 IStateManager 개체의 형식을 식별하는 Type 개체의 순서 있는 배열입니다. 기본 구현은 null를 반환합니다.

예제

다음 코드 예제에는 강력한 형식의 방식을 보여 줍니다 StateManagedCollection 구현 클래스는 GetKnownTypes 메서드. 합니다 CycleCollection 구현의 GetKnownTypes 반환을 Type 비롯 한 알려진 형식의 배열을 BicycleTricycle 형식입니다. 이 코드 예제는에 대해 제공 된 큰 예제의 일부는 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

설명

GetKnownTypes 메서드는 내부적으로 호출 됩니다 합니다 StateManagedCollection 구현에서 컬렉션을 IStateManager.SaveViewState 메서드. 파생된 컬렉션을 재정의 합니다 GetKnownTypes 배열을 반환 하는 방법 Type 형식을 나타내는 개체 컬렉션 포함할 수 있습니다.

적용 대상

추가 정보