2016-07-13 37 views
0

序列化我有像C# - 類獲取不設置

public class ASetting 
{ 
    public Type AType; 
    public string AString; 
} 
在我的項目的設置

類。我只想保存屬性AString。該課程沒有得到保存。我的問題似乎是類型的序列化。嘗試不同的方法後,我感到有點困惑:

而且不工作是capsuling像這樣的屬性:

public class ASetting 
{ 
    private Type AType { get; private set; } 
    public string AString; 
} 

如果我屬性設置爲私有,類被保存,這是working

public class ASetting 
{ 
    private Type AType; 
    public string AString; 
} 

但是我需要有物業A型公衆。所以我試圖用IgnoreDataMemberAttribute

public class ASetting 
{ 
    [IgnoreDataMember] 
    public Type AType; 
    public string AString; 
} 

但這也是不工作

我讀了關於SettingsSerializeAsAttribute - 它看起來像設置序列化的屬性是不一樣的像System.Runtime.Serialisation屬性。

如果任何人有解決我的問題的想法 - 在保存期間忽略屬性類型將greate。

回答

0

你試過[NonSerialized]嗎? 這是Link