Hi all,
In a project I'm currently working on, we've added a wrapper class for accessing the HttpSessionState
object. The trouble is that the current solution means you have to write some code to wrap the functionality. I came up with the following solution
/// <typeparam name="TKey">Class used for generating key into session state storage.</typeparam>
/// <typeparam name="T">Type of object to store.</typeparam>
public static class SessionManager<TKey, T>
{
static SessionManager()
{
_key = typeof(TKey).ToString();
}
private static readonly string _key;
public static string Key
{
get { return _key; }
}
// Other functions ... (Set, IsSet, Remove, etc.)
}
Now you can create the desired storage by merely using
using StringStore= Test.SessionManager<System.Boolean, System.String>;
using StringStore2= Test.SessionManager<System.Version, System.String>;
StringStore.Set("I'm here");
StringStore2.Set("I'm also here");
The code works and is nice in that you can easily create the wrapper class (single using statement) and everything is static. The code is however abusing the type system a bit, so maybe it is a bit to obscure? Before I added it I wanted to get some feedback, so here's the question:
If you we're maintaining said system and encountered the code above, would you
- Hunt down and kill whoever checked the file in?
- Be a bit annoyed by the attempt to be clever, but let it slide?
- Think it was a nice way of avoiding boilerplate code?
Would you prefer to use a text generation tool] like T4?
Thanks for any replies,
Mads