问题描述
我不知道是否有人知道的快捷方式,或如果有人写了一本反映工具告诉一个解决方案,对象不是标记为可序列。我切换一个网站转移到的StateServer和我需要的所有对象标记为可序列。我不想错过任何
I was wondering if anyone knows of a quick way or if anyone has written a reflection tool to tell which objects in a solution are not marked as serializable. I'm switching a site over to a StateServer and i need to have all objects marked as serializable. I don't want to miss any.
此外,第二部分做枚举必须是序列化?
Also, second part do enums have to be serializable?
该网站是一个ASP.NET 1.1的网站与2003年建成VS
The website is an ASP.NET 1.1 site built with VS 2003
推荐答案
枚举本质上是serialisable。
Enums are inherently serialisable.
我写了这个帮手越来越属性关闭对象,可以将行添加到您的应用程序的顶部调用以下code:
I wrote this helper for getting attributes off objects, you could add a line to the top of your application that calls the following code:
var assemblies = GetTheAssembliesFromYourApp();
foreach (var assembly in assemblies)
{
var types = assembly.GetTypes ();
foreach (var type in types)
{
if (AttributeHelper.GetAttrbiute<Serializable> (type) == null)
{
// Log somewhere - this type isn't serialisable...
}
}
}
static class AttributeHelper
{
#region Static public methods
#region GetAttribute
static public T GetAttribute<T> (object obj)
where T : Attribute
{
if (obj == null)
throw new ArgumentNullException ("obj");
// If the object is a member info then we can use it, otherwise it's an instance of 'something' so get it's type...
var member = (obj is System.Reflection.MemberInfo) ? (System.Reflection.MemberInfo)obj : obj.GetType ();
return GetAttributeImpl<T> (member);
}
#endregion GetAttribute
#endregion Static public methods
#region Static methods
#region GetAttributeImpl
static T GetAttributeImpl<T> (System.Reflection.MemberInfo member)
where T : Attribute
{
var attribs = member.GetCustomAttributes (typeof (T), false);
if (attribs == null || attribs.Length == 0)
return null;
return attribs[0] as T;
}
#endregion GetAttributeImpl
#endregion Static methods
}
这篇关于查找未项目[Serializable接口]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!