我需要在我的业务逻辑的某些类中定义一个静态属性或方法,以明确确定哪些类是Session服务的Cache或Cache中的可缓存.我在想,界面中的静态属性或方法是完美的,但C#4.0不支持这一点.
所有需求都能够在通用管理器中评估哪些类是可缓存的,如果是,则在哪个级别:会话(用户)或缓存(应用程序).
现在我正在尝试使用带有T参数的空接口进行评估,但是,可能存在更好的方法?谢谢.
public interface ICacheable<T>
{
}
public class Country : ICacheable<CacheApplication>
{
}
public class Department : ICacheable<CacheUser>
{
}
public class Gestor<T>
{
// ...
if (typeof(T) is ICacheable<CacheApplication>)
{
}
// ...
}
Run Code Online (Sandbox Code Playgroud)