0
"XML文書にエラーがあります"というメッセージが表示されます。DictionaryEntry []プロパティのXMLエラーのシリアル化
Code:each key/value用pairの
private readonly SortedList<string, object> _attributes;
[XmlArray("Attributes")]
[XmlArrayItem("AttributesLine", Type=typeof(DictionaryEntry))]
public DictionaryEntry[] _x_Attributes
{
get
{
DictionaryEntry[] ret = new DictionaryEntry[_attributes.Count];
int i=0;
foreach (KeyValuePair<string, object> stuffLine in _attributes)
{
object value = stuffLine.Value; // <--- float[]
ret[i++] = new DictionaryEntry {Key = stuffLine.Key, Value = value};
}
return ret;
}
set
{
_attributes.Clear();
foreach (DictionaryEntry entry in value)
{
_attributes.Add((string) entry.Key, entry.Value);
}
}
}
valueは[] typeのfloatのある。私はまだいくつかのキーがfloat []以外の型の値を持つことができるように、値の型を 'System.Object'のままにしておきたいと思います(いずれの場合でも、辞書に1つのエントリが設定されていても例外が発生します)。
明確にするために編集:私は 'XmlSerializer'を使用していますが、entry.Valueが 'float'のときはうまくいきました。
ありがとうございますが、シリアライザを交換するのは難しいです。また、現在は単一の浮動小数点値で動作します。 – alhazen