我不知道是否有人知道的快捷方式,或者是否有人寫了一個反思工具告訴溶液中的哪些對象未標記爲可序列化。我正在將一個站點切換到一個StateServer,並且我需要將所有對象標記爲可序列化。我不想錯過任何。查找不在項目[Serializable接口]
此外,第二部分不枚舉必須是序列化?
該網站是用VS 2003構建的ASP.NET 1.1網站
我不知道是否有人知道的快捷方式,或者是否有人寫了一個反思工具告訴溶液中的哪些對象未標記爲可序列化。我正在將一個站點切換到一個StateServer,並且我需要將所有對象標記爲可序列化。我不想錯過任何。查找不在項目[Serializable接口]
此外,第二部分不枚舉必須是序列化?
該網站是用VS 2003構建的ASP.NET 1.1網站
枚舉本身serialisable。
我寫了這個幫手越來越屬性關閉對象,你可以一行添加到您的應用程序的頂部調用以下代碼:
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
}
Enum需要可序列化。
要搞清楚什麼是不可序列化,我有單元測試這些對象,只需調用知道,如果它是序列化的方法。該方法嘗試序列,如果失敗了,對象是不是...
public static Stream serialize<T>(T objectToSerialize)
{
MemoryStream mem = new MemoryStream();
BinaryFormatter b = new BinaryFormatter();
b.Serialize(mem, objectToSerialize);
return mem;
}
在你單元測試,你需要調用序列化(objectToCheck);如果不是可以分解的話,將會引發異常。
兩件事情,一個是有沒有辦法做到這一點的地方搜索整個解決方案?二,我的解決方案是一個ASP.NET 1.1的網站,使用VS 2003,我從來沒有在此修建了舊的環境測試,可以嗎? – bendewey 2008-12-13 15:11:39
整體解決方案不應該是所有的連載。你應該能夠選擇什麼類別。和VS2003允許測試...單元測試不在VS(如Nunit) – 2008-12-13 15:21:21