IStateFormatter.Deserialize(String) 方法

定义

从对象状态图的序列化字符串形式对其进行反序列化。

public:
 System::Object ^ Deserialize(System::String ^ serializedState);
public object Deserialize (string serializedState);
abstract member Deserialize : string -> obj
Public Function Deserialize (serializedState As String) As Object

参数

serializedState
String

IStateFormatter 会将其反序列化为初始化对象的字符串。

返回

Object

表示 ASP.NET 服务器控件状态的对象。

示例

下面的代码示例演示如何 Deserialize 加载视图状态信息。 类 Load 的方法 StreamPageStatePersister 使用 IStateFormatterPageStatePersister 类继承的接口反序列化视图状态。 此代码示例是为接口提供的大型示例的 IStateFormatter 一部分。

//
// Load ViewState and ControlState.
//
public override void Load()
{
    Stream stateStream = GetSecureStream();

    // Read the state string, using the StateFormatter.
    StreamReader reader = new StreamReader(stateStream);

    IStateFormatter formatter = this.StateFormatter;
    string fileContents = reader.ReadToEnd();

    // Deserilize returns the Pair object that is serialized in
    // the Save method.
    Pair statePair = (Pair)formatter.Deserialize(fileContents);

    ViewState = statePair.First;
    ControlState = statePair.Second;
    reader.Close();
    stateStream.Close();
}
'
' Load ViewState and ControlState.
'
Public Overrides Sub Load()

    Dim stateStream As Stream
    stateStream = GetSecureStream()

    ' Read the state string, using the StateFormatter.
    Dim reader As New StreamReader(stateStream)

    Dim serializedStatePair As String
    serializedStatePair = reader.ReadToEnd
    Dim statePair As Pair

    Dim formatter As IStateFormatter
    formatter = Me.StateFormatter

    ' Deserilize returns the Pair object that is serialized in
    ' the Save method.      
    statePair = CType(formatter.Deserialize(serializedStatePair), Pair)

    ViewState = statePair.First
    ControlState = statePair.Second
    reader.Close()
    stateStream.Close()
End Sub

注解

使用该方法Deserialize重新构造已使用Serialize该方法序列化的 ASP.NET 页或服务器控件的状态对象。

适用于