Monday, June 16, 2014

C# getsetters which tuck away stuff to session

public List<Foo> Foos
{
   get
   {
      if (HttpContext.Current.Session[SessionKeys.FooKey] == null) return null;
      return HttpContext.Current.Session[SessionKeys.FooKey] as List<Foo>;
   }
   set { HttpContext.Current.Session[SessionKeys.FooKey] = value; }
}
 
public int MyId
{
   get
   {
      if (HttpContext.Current.Session[SessionKeys.MyKey] == null)
         HttpContext.Current.Session[SessionKeys.MyKey] = -1;
      return (int)HttpContext.Current.Session[SessionKeys.MyKey];
   }
   set { HttpContext.Current.Session[SessionKeys.MyKey] = value; }
}

No comments:

Post a Comment