【发布时间】:2017-02-22 02:55:02
【问题描述】:
我有一个派生类,它只向基类添加方法,我想将它序列化为其基类,我遇到的问题是这是一个游戏模组,我无法修改基类直接将 XmlInclude 添加到基础。
namespace CustomNPC
{
public class CustomNPCInteract : NPC
{
public CustomNPCInteract()
:base()
{
this.initializeNPC();
}
public CustomNPCInteract(AnimatedSprite sprite, Vector2 position, string defaultMap, int facingDir, string name, bool dateable, Dictionary<int, int[]> schedule, Texture2D portrait)
: base(sprite, position, defaultMap, facingDir, name, dateable, schedule, portrait)
{
this.initializeNPC();
}
public CustomNPCInteract(AnimatedSprite sprite, Vector2 position, int facingDir, string name, StardewValley.LocalizedContentManager manager = null)
:base(sprite, position, facingDir, name, manager)
{
this.initializeNPC();
}
private void initializeNPC()
{
this.age = 2; //child
this.manners = 2; //rude
this.socialAnxiety = 1; //shy
this.optimism = 1; //negative
this.gender = 1; //female
this.datable = false; //not-datable
this.homeRegion = 0; //Other
this.birthday_Season = "fall"; //fall 8
this.birthday_Day = 8;
}
}
}
我的命名空间和类是如何设置的。 CustomNPCInteract 继承 NPC,我希望它像任何其他 NPC 一样序列化,但无法修改该特定类。
任何帮助将不胜感激
【问题讨论】:
标签: c# .net xml serialization