public FileCacheItem Deserialize(Stream stream) { var surrogateSelector = new AnonymousTypeSurrogateSelector(); surrogateSelector.AddSurrogate(typeof(CacheItemPolicy), new StreamingContext(StreamingContextStates.All), new CacheItemPolicySurrogate()); BinaryFormatter formatter = new BinaryFormatter(); formatter.SurrogateSelector = surrogateSelector; formatter.Binder = _binder; FileCacheItem item = null; try { string key = (string)formatter.Deserialize(stream); CacheItemPolicy policy = (CacheItemPolicy)formatter.Deserialize(stream); object payload = formatter.Deserialize(stream); item = new FileCacheItem(key, policy, payload); } catch (SerializationException) { } return(item); }
public FileCacheItem Deserialize(Stream stream) { var surrogateSelector = new AnonymousTypeSurrogateSelector(); surrogateSelector.AddSurrogate(typeof(CacheItemPolicy), new StreamingContext(StreamingContextStates.All), new CacheItemPolicySurrogate()); BinaryFormatter formatter = new BinaryFormatter(); formatter.SurrogateSelector = surrogateSelector; formatter.Binder = _binder; FileCacheItem item = null; try { string key = (string)formatter.Deserialize(stream); CacheItemPolicy policy = (CacheItemPolicy)formatter.Deserialize(stream); object payload = formatter.Deserialize(stream); item = new FileCacheItem(key, policy, payload); } catch (SerializationException) { } return item; }
public void Serialize(Stream stream, FileCacheItem cacheItem) { var surrogateSelector = new AnonymousTypeSurrogateSelector(); surrogateSelector.AddSurrogate(typeof(CacheItemPolicy), new StreamingContext(StreamingContextStates.All), new CacheItemPolicySurrogate()); BinaryFormatter formatter = new BinaryFormatter(); formatter.SurrogateSelector = surrogateSelector; formatter.Serialize(stream, cacheItem.Key); formatter.Serialize(stream, cacheItem.Policy); formatter.Serialize(stream, cacheItem.Payload); }