オブジェクトのジェネリック リストをシリアル化しようとすると、派生クラスで使用される変数のデータが失われます。以前は派生クラスにこれらの変数がありましたが、基本クラスがシリアル化されていたため、派生変数は無視されると想定していました。
コード:
[XmlInclude(typeof(AchievementStock))]
[XmlInclude(typeof(AchievementCash))]
[XmlInclude(typeof(AchievementStockSpecify))]
public abstract class Achievement : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
protected string _title;
protected string _description;
protected int _cashValue;
protected bool _completed;
//Cash
protected int _amountCash;
protected bool _greater;
//Stocks
protected int _amountStocks;
//StockSpecify
protected string _stockName;
protected int _amount;
public abstract void CheckAchievement(AssetManager assetManager, AchievementManager achievementManager);
public Achievement()
{
}
public Achievement(string title, string description, int cashValue, bool completed)
{
Title = title;
Description = description;
_cashValue = cashValue;
_completed = completed;
}
public void PropertyChangedEvent(string assetName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(assetName));
}
}
}
public class AchievementCash : Achievement
{
public AchievementCash(string title, string description, int cashValue, bool completed, int amountCash, bool greater)
: base(title, description, cashValue, completed)
{
_amountCash = amountCash;
_greater = greater;
}
public AchievementCash()
{
}
public override void CheckAchievement(AssetManager assetManager, AchievementManager achievementManager)
{
}
}
public class AchievementStock : Achievement
{
public AchievementStock(string title, string description, int cashValue, bool completed, int amountStocks)
: base(title, description, cashValue, completed)
{
_amountStocks = amountStocks;
}
public AchievementStock()
{
}
public override void CheckAchievement(AssetManager assetManager, AchievementManager achievementManager)
{
}
}
public class AchievementStockSpecify : Achievement
{
public AchievementStockSpecify(string title, string description, int cashValue, bool completed, string stockName, int amount)
: base(title, description, cashValue, completed)
{
_stockName = stockName;
_amount = amount;
}
public AchievementStockSpecify()
{
}
public override void CheckAchievement(AssetManager assetManager, AchievementManager achievementManager)
{
}
}
デフォルト値になる変数は次のとおりです。
//Cash
protected int _amountCash;
protected bool _greater;
//Stocks
protected int _amountStocks;
//StockSpecify
protected string _stockName;
protected int _amount;
なぜこれが起こっているのか、誰にもアイデアがありますか?