Skip to content

Instantly share code, notes, and snippets.

@glikoz
Created June 26, 2012 00:24
Show Gist options
  • Save glikoz/2992302 to your computer and use it in GitHub Desktop.
Save glikoz/2992302 to your computer and use it in GitHub Desktop.
ServiceStack UserAuthExtensions
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