我正在尝试从xml文件反序列化一些设置.有问题的属性/底层字段是一个被调用的字段AlertColors.我将基础字段初始化为白色,黄色和红色,以确保此类的新实例具有有效的颜色设置.但是当我反序列化时,_colorArgb最后得到六个值,前三个是初始化值,后三个是从xml文件中读取的值.但该财产AlertColors不会附加到该领域,而是改变其元素.为什么我最终得到六种颜色的场?
这是代码:
private List<int> _colorArgb = new List<int>(new int[] { Color.White.ToArgb(), Color.Yellow.ToArgb(), Color.Red.ToArgb() });
public List<int> AlertColors
{
get
{
return _colorArgb;
}
set
{
for (int i = 0; i < Math.Min(_colorArgb.Count, value.Count); i++)
{
if (_colorArgb[i] != value[i])
{
HasChanged = true;
}
}
_colorArgb = value;
}
}
public bool Deserialize(string filePath)
{
if (!File.Exists(filePath))
{
Logger.Log("Error while loading the settings. File does not exist.");
return false;
}
FileStream fileStream = …Run Code Online (Sandbox Code Playgroud)