// IStateContainer Members // <summary> // Merges the content of the state object with the content of this class // </summary> // <param name="state">State object to apply</param> public void RestoreState(object state) { string serializedStates = state as string; if (string.IsNullOrEmpty(serializedStates)) { return; } string[] stateArray = serializedStates.Split(';'); if (stateArray == null || stateArray.Length == 0) { return; } foreach (string stateString in stateArray) { PersistedState deserializedState = DeserializeState(stateString); if (deserializedState == null) { Debug.Fail("Invalid state. Deserialization failed: " + stateString); continue; } _persistedStates[deserializedState.Key] = deserializedState; } }
// <summary> // Gets the state for the specified key. If not found, a default state object is // created and returned. // </summary> // <param name="key">Key to look up</param> // <returns>Guaranteed non-null result</returns> protected PersistedState GetState(object key) { PersistedState state = null; if (!_persistedStates.TryGetValue(key, out state)) { state = CreateDefaultState(key); Fx.Assert(state != null, "CreateDefaultState() should always return a value"); _persistedStates[key] = state; } return(state); }