StateManagedCollection.GetKnownTypes Yöntem

Tanım

Türetilmiş bir sınıfta geçersiz kılındığında, koleksiyonun IStateManager içerebileceği bir tür StateManagedCollection dizisi alır.

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()

Döndürülenler

Type[]

Koleksiyonun Type içerebileceği nesne türlerini IStateManager tanımlayan sıralı bir nesne dizisi. Varsayılan uygulama döndürür null.

Örnekler

Aşağıdaki kod örneği, türü kesin olarak belirlenmiş StateManagedCollection bir sınıfın yöntemini nasıl uyguladığını GetKnownTypes gösterir. CycleCollection uygulamasıGetKnownTypes, ve Tricycle türleri de dahil olmak üzere Bicycle bilinen türlerden oluşan bir Type dizi döndürür. Bu kod örneği, sınıfı için StateManagedCollection sağlanan daha büyük bir örneğin parçasıdır.

//////////////////////////////////////////////////////////////
//
// 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

Açıklamalar

GetKnownTypes yöntemi, yönteminin StateManagedCollection uygulanmasında koleksiyon tarafından dahili olarak çağrılırIStateManager.SaveViewState. Türetilmiş koleksiyonlar, koleksiyonun GetKnownTypes Type içerebileceği türleri temsil eden bir nesne dizisi döndürmek için yöntemini geçersiz kılar.

Şunlara uygulanır

Ayrıca bkz.