StateManagedCollection.SetDirtyObject(Object) Méthode

Définition

En cas de substitution dans une classe dérivée, commande à un object contenu dans la collection d'enregistrer l'intégralité de son état dans l'état d'affichage, plutôt que d'enregistrer uniquement des informations relatives aux modifications.

protected:
 abstract void SetDirtyObject(System::Object ^ o);
protected abstract void SetDirtyObject (object o);
abstract member SetDirtyObject : obj -> unit
Protected MustOverride Sub SetDirtyObject (o As Object)

Paramètres

o
Object

IStateManager qui doit se sérialiser intégralement.

Exemples

L’exemple de code suivant montre comment une classe fortement typée StateManagedCollection implémente la méthode abstraite SetDirtyObject . L’objet CycleCollection utilise un StateBag objet pour stocker ses informations d’état d’affichage et délègue simplement l’appel à la SetDirty méthode de l’objet StateBag . Cet exemple de code fait partie d’un exemple plus grand fourni pour la StateManagedCollection classe.

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

Remarques

La SetDirtyObject méthode est appelée en interne par le IStateManager.SaveViewState, IList.Addet IList.Insert les méthodes.

S’applique à

Voir aussi