Created
October 5, 2011 14:12
-
-
Save geoffreysmith/1264520 to your computer and use it in GitHub Desktop.
TempDataExtensions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class TempDataExtension | |
{ | |
public static void Put(this TempDataDictionary tempData, string key, object value) | |
{ | |
var js = new JavaScriptSerializer(); | |
tempData[key] = js.Serialize(value); | |
} | |
public static T Get<T>(this TempDataDictionary tempData, string key) where T : class | |
{ | |
var js = new JavaScriptSerializer(); | |
object slug; | |
tempData.TryGetValue(key, out slug); | |
return slug == null ? null : js.Deserialize<T>((string)slug); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment