If I understand your question correctly, you just need some kind of global storage for certain values in your program.
You can create a static class with public static properties for the various values that you need to store and be able to globally access inside your application. Something like:
public static class Global
{
private string s_sSomeProperty;
static Globals ()
{
s_sSomeProperty = ...;
...
}
public static string SomeProperty
{
get
{
return ( s_sSomeProperty );
}
set
{
s_sSomeProperty = value;
}
}
...
}
This way you can just write Global.SomeProperty
anywhere in your code where the Global
class is available.
Of course, you'd need validation and - if your application is multithreaded - proper locking to make sure your global (shared) data is protected across threads.
This solution is better than using something like session because your properties will be strongly typed and there's no string-based lookup for the property value.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…