public void Serialize(object obj, Altaxo.Serialization.Xml.IXmlSerializationInfo info) { var s = (PropertyBagLazyLoaded)obj; var assemblyVersion = s.GetType().Assembly.GetName().Version; var keyList = new HashSet <string>(); foreach (var entry in s._properties) { if (entry.Key.StartsWith(TemporaryPropertyPrefixString)) { continue; } if (!info.IsSerializable(entry.Value)) { continue; } keyList.Add(entry.Key); } foreach (var entry in s._propertiesLazyLoaded) { if (entry.Key.StartsWith(TemporaryPropertyPrefixString)) { continue; } keyList.Add(entry.Key); } info.CreateArray("Properties", keyList.Count); info.AddAttributeValue("AssemblyVersion", assemblyVersion.ToString()); foreach (var key in keyList) { // Since this is a lazy bag, each property is deserialized individually. Thus we must serialize it individually, too. // ClearProperties clears all properties left by former serializations so that each item is serialized as if serialized individually. info.ClearProperties(); info.CreateElement("e"); info.AddValue("Key", key); if (s._properties.TryGetValue(key, out var value)) { info.AddValue("Value", value); } else if (s._propertiesLazyLoaded.TryGetValue(key, out var rawXml)) { info.WriteRaw(rawXml); } else { throw new InvalidOperationException("Key neither found in regular properties nor in lazy loaded properties"); } info.CommitElement(); } info.CommitArray(); }