我有一個.net 4類,它用ReadOnly屬性裝飾。我試圖在.NET Compact 3.5項目中序列化這個類,但我得到一個錯誤: 「有一個錯誤,反映類型IpSettings」 據我所知.NET CF不包括任何自定義屬性,但我不需要序列化這個屬性。有沒有辦法跳過屬性序列化? 謝謝, 亞歷 .net compact framework deserialization
public class IpSettings
{
[ReadOnly(true)]
public string IP { get; set; }
public string Mask { get; set; }
public string Gateway { get; set; }
public string DNS1 { get; set; }
public string DNS2 { get; set; }
}
變種串行=新System.Xml.Serialization.XmlSerializer(typeof運算(IpSettings));
我想序列化IP屬性,但沒有[ReadOnly(true)]屬性。 [System.Xml.Serialization.XmlIgnore]將完全忽略序列化的IP屬性。 – 2012-07-26 13:04:50
對不起亞歷克斯。我完全錯誤地解釋你在問什麼。我不知道爲什麼你需要你所要求的,因爲xmlserialization不會序列化任何對象元數據,如屬性。 – pdriegen 2012-07-26 13:13:39
問題我相信它不是用序列化,而是用反射。 當XmlSerializer嘗試反映IpSettings類時,它失敗了,因爲在.net CF中沒有屬性爲[ReadOnly]。這是我的猜測。 – 2012-07-26 13:15:50