Skip to content

Instantly share code, notes, and snippets.

@glikoz
Created June 26, 2012 00:24

Revisions

  1. glikoz revised this gist Jun 26, 2012. 1 changed file with 13 additions and 1 deletion.
    14 changes: 13 additions & 1 deletion UserAuthExtensions.cs
    Original file line number Diff line number Diff line change
    @@ -16,9 +16,21 @@ public static T Get<T>(this UserAuth userAuth)
    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);
    }
    }
    }
    }
  2. glikoz revised this gist Jun 26, 2012. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions UserAuthExtensions.cs
    Original file line number Diff line number Diff line change
    @@ -9,14 +9,14 @@ namespace ServiceStack.ServiceInterface.Auth
    {
    public static class UserAuthExtensions
    {
    public T Get<T>(this UserAuth userAuth)
    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 void Set<T>(this UserAuth userAuth, T value)
    public static void Set<T>(this UserAuth userAuth, T value)
    {
    userAuth.Meta[typeof(T).Name] = TypeSerializer.SerializeToString(value);
    }
  3. glikoz created this gist Jun 26, 2012.
    24 changes: 24 additions & 0 deletions UserAuthExtensions.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    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 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 void Set<T>(this UserAuth userAuth, T value)
    {
    userAuth.Meta[typeof(T).Name] = TypeSerializer.SerializeToString(value);
    }
    }
    }