Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions src/Libraries/CoreNodeModels/Input/CustomSelection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,5 +147,53 @@ private void OnSerializing(StreamingContext context)
{
serializedItems = Items.ToList();
}

protected override void SerializeCore(XmlElement nodeElement, SaveContext context)
{
base.SerializeCore(nodeElement, context);

if (context == SaveContext.Copy)
{
var doc = nodeElement.OwnerDocument;

foreach (var item in Items)
{
var itemElement = doc.CreateElement("CustomItem");
itemElement.SetAttribute("Name", item.Name);
itemElement.SetAttribute("Value", item.Item?.ToString() ?? string.Empty);
nodeElement.AppendChild(itemElement);
}
}
}

protected override void DeserializeCore(XmlElement nodeElement, SaveContext context)
{
base.DeserializeCore(nodeElement, context);

if (context == SaveContext.Copy)
{
Items.Clear();
foreach (XmlNode child in nodeElement.ChildNodes)
{
if (child is XmlElement itemElement && itemElement.Name == "CustomItem")
{
var name = itemElement.GetAttribute("Name");
var value = itemElement.GetAttribute("Value");
Items.Add(new DynamoDropDownItem(name, value));
}
}
// Restore the selected index from the attribute
var attrib = nodeElement.Attributes["index"];
if (attrib != null && Items.Count > 0)
{
var indexStr = attrib.Value;
SelectedIndex = ParseSelectedIndex(indexStr, Items);
}
else
{
SelectedIndex = 0;
}
}
}
}
}
Loading