andrew4582

SessionHelper

Aug 18th, 2010
454
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.64 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Text;
  6. using System.Web;
  7. using System.IO;
  8.  
  9. namespace Core.Web {
  10.     public static class SessionHelper {
  11.        
  12.         public static T GetValue<T>(this HttpSessionStateBase session,string name,T valueIfNull = default(T)) {
  13.            
  14.             object raw = session[name];
  15.            
  16.             if(raw == null)
  17.                 return valueIfNull;
  18.            
  19.             T value = (T)raw;
  20.            
  21.             if(value == null)
  22.                 return valueIfNull;
  23.  
  24.             return value;
  25.  
  26.         }    
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment