mirror of
https://git.teknik.io/Teknikode/Teknik.git
synced 2023-08-02 14:16:22 +02:00
24 lines
640 B
C#
24 lines
640 B
C#
|
using Microsoft.AspNetCore.Http;
|
|||
|
using Newtonsoft.Json;
|
|||
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Text;
|
|||
|
|
|||
|
namespace Teknik.Utilities
|
|||
|
{
|
|||
|
public static class SessionExtensions
|
|||
|
{
|
|||
|
public static void Set<T>(this ISession session, string key, T value)
|
|||
|
{
|
|||
|
session.SetString(key, JsonConvert.SerializeObject(value));
|
|||
|
}
|
|||
|
|
|||
|
public static T Get<T>(this ISession session, string key)
|
|||
|
{
|
|||
|
var value = session.GetString(key);
|
|||
|
return value == null ? default(T) :
|
|||
|
JsonConvert.DeserializeObject<T>(value);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|