公共财产的设定者分配"值"时的序列化错误到一个集合

时间:2016-03-01 02:55:48

标签: c# xml serialization xml-serialization xmlserializer

我知道这导致错误,但我不明白为什么以及如何解决它。我正在寻找避免创建数百个变量的方法

  • is1_BufferUAbsolute
  • is2_BufferUAbsolute
  • ...
  • is75_BufferUAbsolute

将其替换为

initialStopCollection [n]的.BufferUAbsolute

Serialization Error

1 个答案:

答案 0 :(得分:0)

您的代码应更改为:

set
{
    int itemIndex = 1;
    if (initialStopCollection == null) initialStopCollection = new ...; // your initialStopCollection is null. Create new one
    if (itemIndex >= initialStopCollection.Count) // Two few items, create new
    {
        for (int i = initialStopCollection.Count; i <= itemIndex; i++)
        {
            initialStopCollection.Add(new ...);
        }
    }
    if (initialStopCollection[itemIndex] == null) initialStopCollection[itemIndex] = new ... ; // This item is not initialized, create new
    initialStopCollection[itemIndex].BufferUAbsolute = value;
}