IStateFormatter.Deserialize(String) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
將已序列化成字串形式的物件狀態圖還原序列化。
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 還原序列化為初始化物件的字串。
傳回
代表 ASP.NET 伺服器控制項狀態的物件。
範例
下列程式碼範例示範方法如何 Deserialize 載入檢視狀態資訊。 類別 Load 的 StreamPageStatePersister
方法會使用 IStateFormatter 繼承自 類別的 PageStatePersister 介面來還原序列化檢視狀態。 此程式碼範例是介面所提供較大範例的 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 網頁或伺服器控制項的狀態物件。