Beispiel #1
0
        private void addNodeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            dynamic target = treeView1.SelectedNode == null ? byml : treeView1.SelectedNode.Tag;

            var targetNodeCollection = treeView1.SelectedNode == null ? treeView1.Nodes : treeView1.SelectedNode.Nodes;

            if (target is EditableNode)
            {
                if (treeView1.SelectedNode.Parent == null)
                {
                    target = byml;
                    targetNodeCollection = treeView1.Nodes;
                }
                else
                {
                    target = treeView1.SelectedNode.Parent.Tag;
                    targetNodeCollection = treeView1.SelectedNode.Parent.Nodes;
                }
            }

            var newProp = AddBymlPropertyDialog.newProperty(!(target is IList <dynamic>));

            if (newProp == null)
            {
                return;
            }
            bool clone = newProp.Item2 is IDictionary <string, dynamic> || newProp.Item2 is IList <dynamic>; //reference types must be manually cloned
            var  toAdd = clone ? DeepCloneDictArr.DeepClone(newProp.Item2) : newProp.Item2;

            targetNodeCollection.Clear();

            if (target is IList <dynamic> )
            {
                ((IList <dynamic>)target).Insert(((IList <dynamic>)target).Count, toAdd);
                parseArrayNode((IList <dynamic>)target, targetNodeCollection);
            }
            else if (target is IDictionary <string, dynamic> )
            {
                ((IDictionary <string, dynamic>)target).Add(newProp.Item1, toAdd);
                parseDictNode((IDictionary <string, dynamic>)target, targetNodeCollection);
            }
            else
            {
                throw new Exception();
            }

            ResetValues();
        }
 public Tuple <string, dynamic> GetNewProperty(dynamic target) => AddBymlPropertyDialog.newProperty(target is IDictionary <string, dynamic>);