親愛的堆棧溢出社區, 我想我永遠不會問這個問題,但顯然是序列化或我的用法出了問題。對象序列化問題(c#)
我有一個類,我需要序列:
[Serializable]
public class Device : ISerializable, IDisposable
{
public delegate void ListChangedEventHandler(object sender, ListChangedEventArgs e);
public string Name { get; set; }
public string Description { get; set; }
public string IPAddress { get; set; }
[Browsable(false)]
public ThreadSafeBindingList<Item> Items { get; set; }
[Browsable(false)]
public MibEntity AssociatedMibEntity { get; set; }
//methods etc.
}
一點解釋:
ThreadSafeBindingList從System.ComponentModel.BindingList MibEntity繼承是一類SharpSNMP庫(http://sharpsnmplib.codeplex.com/ )
問題: 當我嘗試t反序列化對象,MibEntity始終爲空。其他屬性都很好。 MibEntity類在外部的dll中,我在Device類所在的項目中引用它。
這是它的內容:
[Serializable]
public class MibEntity
{
public MibEntity()
{
Children = new List<MibEntity>();
}
[Browsable(false)]
public List<MibEntity> Children { get; set; }
[Browsable(true)]
[Category("General")]
public string OID { get; set; }
private string _name;
[Browsable(true)]
[Category("General")]
public string Name
{
get { return _name; }
set { _name = value; }
}
[Browsable(true)]
public string Description { get; set; }
[Browsable(false)]
public int Value { get; set; }
[Browsable(true)]
public AccessType AccessType { get; set; } //this is enum from SharpSNMP library
[Browsable(true)]
public Status Status { get; set; } //this is enum from same assembly as this class
[Browsable(true)]
public string Syntax { get; set; }
[Browsable(true)]
public bool IsTableEntry { get; set; }
[Browsable(true)]
public IDefinition IDefinition { get; set; } //this is interface from SharpSNMP library
}
我使用的BinaryFormatter序列化和反序列化。 謝謝你的幫助!
由於您通過'ISerializable'自定義序列化,我們需要同時看到自定義的'GetObjectData'方法和自定義的反序列化構造函數。 –