是否有可能有一个编译时检查一个类型是标有Seri​​alizable属性有可能、有一个、标有、属性

由网友(大眼萌嘟宝)分享简介:具体来说,我们正在做的进程外会话状态服务器的保存在会话中的所有类型都必须是可序列化我们的应用程序兼容。 有没有办法看到的,任何类型的投入HttpSessionState标有Seri​​alizable属性的编译时间。沿着这种非有效code东西线公共静态无效把< T>(字符串键,T值),其中T:IsMarke...

具体来说,我们正在做的进程外会话状态服务器的保存在会话中的所有类型都必须是可序列化我们的应用程序兼容。

有没有办法看到的,任何类型的投入HttpSessionState标有Seri​​alizable属性的编译时间。沿着这种非有效code东西线

 公共静态无效把< T>(字符串键,T值),其中T:IsMarkedWitheSerializableAttribute
{
   HttpContext.Current.Session [关键] =价值;
}
 

解决方案

您可以编写一个自定义的FxCop规则生成这种情况下警告。

贾森阻止对他的网站一个示例规则。

Specifically we're making our application compatible with the Out Of Process Session State server where all types saved in session must be serializable.

Is there a way to see at compile time that any type put into HttpSessionState is marked with the Serializable attribute. Something along the lines of this 'non-valid' code

public static void Put<T>( string key, T value ) where T : IsMarkedWitheSerializableAttribute
{
   HttpContext.Current.Session[key] = value;
}

解决方案

You could write a custom FxCop rule to generate warnings for this scenario.

Jason Block has a sample rule on his site.

阅读全文

相关推荐

最新文章