public static void StoreData <T>( this ITempDataDictionary tempData, T data) { if (data == null) { return; } string entryKey = data.GetType().Name; string value = JsonConvert.SerializeObject(data); byte[] bytes = TempDataExtensions.Compress(value); if (bytes != null) { value = Convert.ToBase64String(bytes); tempData[entryKey] = value; } }
public static bool TryLoadData <T>( this ITempDataDictionary tempData, out T data) { data = default(T); string entryKey = typeof(T).Name; if (tempData.ContainsKey(entryKey)) { string value = tempData[entryKey] as string; byte[] bytes = Convert.FromBase64String(value); value = TempDataExtensions.Decompress(bytes); data = JsonConvert.DeserializeObject <T>(value); tempData.Remove(entryKey); return(true); } return(false); }