StateManagedCollection.SetDirtyObject(Object) 方法

定义

在派生类中替代时,指示集合包含的 object 将其全部状态记录到视图状态,而不是仅记录更改信息。

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)

参数

o
Object

应对其自身进行完全序列化的 IStateManager

示例

下面的代码示例演示强类型 StateManagedCollection 类如何实现抽象 SetDirtyObject 方法。 CycleCollection使用 StateBag 对象来存储其视图状态信息,并简单地委托对 对象的 方法的StateBag调用SetDirty。 此代码示例是为 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

注解

方法 SetDirtyObjectIStateManager.SaveViewStateIList.AddIList.Insert 方法在内部调用。

适用于

另请参阅