I\'m missing a trick here I think and can\'t believe I\'ve never done this before. However, how can I cast a generic type using the as keyword?
[Serializable]
pu
where T : class, ISessionManager
you can go even further
where T : class, ISessionManager, new()
this will force non abstract class with parameterless ctor to be handed in as T
Read up on Constraints on Type Parameters in C#.
In this particular case, you must ensure that T is a class:
public abstract class SessionManager<T>
where T : class, ISessionManager
... where T : class, ISessionManager
In case you want to use the where keyword
on methods here is an example that also uses generics
public void store<T>(T value, String key)
{
Session[key] = value;
}
public T retrieve<T>(String key) where T:class
{
return Session[key] as T ;
}