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(); }
public void Serialize(object obj, Altaxo.Serialization.Xml.IXmlSerializationInfo info) { var s = (ColorSet)obj; info.SetProperty(GetSerializationRegistrationKey(s), "True"); // Register a property to note that this color set is already serialized. info.AddValue("Name", s._name); info.CreateArray("Colors", s._innerList.Length); foreach (NamedColor c in s) { info.CreateElement("e"); info.AddAttributeValue("Name", c.Name); info.SetNodeContent(c.Color.ToInvariantString()); info.CommitElement(); } info.CommitArray(); }
public void Serialize(object obj, Altaxo.Serialization.Xml.IXmlSerializationInfo info) { var s = (PropertyBag)obj; var keyList = new List <string>(s._properties.Count); foreach (var entry in s._properties) { if (entry.Key.StartsWith(TemporaryPropertyPrefixString)) { continue; } if (!info.IsSerializable(entry.Value)) { continue; } keyList.Add(entry.Key); } info.CreateArray("Properties", keyList.Count); info.AddAttributeValue("AssemblyVersion", s.GetType().Assembly.GetName().Version.ToString()); foreach (var key in keyList) { var value = s._properties[key]; info.CreateElement("e"); info.AddValue("Key", key); if (s._propertiesLazyLoaded.Contains(key) && value is string rawXml) { info.WriteRaw(rawXml); } else { info.AddValue("Value", value); } info.CommitElement(); } info.CommitArray(); }