Created
June 26, 2012 00:24
-
-
Save glikoz/2992302 to your computer and use it in GitHub Desktop.
ServiceStack UserAuthExtensions
This file contains 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
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using ServiceStack.ServiceInterface.Auth; | |
using ServiceStack.Text; | |
namespace ServiceStack.ServiceInterface.Auth | |
{ | |
public static class UserAuthExtensions | |
{ | |
public static T Get<T>(this UserAuth userAuth) | |
{ | |
string str; | |
userAuth.Meta.TryGetValue(typeof(T).Name, out str); | |
return str == null ? default(T) : TypeSerializer.DeserializeFromString<T>(str); | |
} | |
public static T Get<T>(this UserAuth userAuth, string field) | |
{ | |
string str; | |
userAuth.Meta.TryGetValue(field, out str); | |
return str == null ? default(T) : TypeSerializer.DeserializeFromString<T>(str); | |
} | |
public static void Set<T>(this UserAuth userAuth, T value) | |
{ | |
userAuth.Meta[typeof(T).Name] = TypeSerializer.SerializeToString(value); | |
} | |
public static void Set<T>(this UserAuth userAuth,string field,T value) | |
{ | |
userAuth.Meta[field] = TypeSerializer.SerializeToString(value); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment