StateManagedCollection.GetKnownTypes 메서드

정의

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

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[]

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

예제

다음 코드 예제에서는 강력한 형식 StateManagedCollection 의 클래스 메서드를 구현 하는 방법을 보여 줍니다 GetKnownTypes . 구현 CycleCollectionGetKnownTypes 알려진 형식의 배열(포함 및 형식)TypeBicycle 반환 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

설명

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

적용 대상

추가 정보