public NodeNameCommand(NodeNameChange change)
     : base(change)
 {
 }
        private void OnBeforeChange(object sender, XObjectChangeEventArgs e)
        {
            var node = sender as XObject;

            // We do not allow editing DTDs through XmlModel
            if (node is XDocumentType)
            {
                var msg = String.Format(CultureInfo.CurrentCulture, Resources.VanillaProvider_DtdNodesReadOnly);
                throw new NotSupportedException(msg);
            }
            var action = e.ObjectChange;
            currentChange = null;

            XElement element = null;
            XAttribute attribute = null;
            XText text = null;
            XProcessingInstruction pi = null;
            XComment comment = null;

            switch (action)
            {
                case XObjectChange.Add:
                    var addChange = new AddNodeChangeInternal(node, action);
                    currentChange = addChange;
                    break;
                case XObjectChange.Remove:
                    var removeChange = new RemoveNodeChange(node, action);
                    removeChange.Parent = node.Parent;
                    if (removeChange.Parent == null)
                    {
                        removeChange.Parent = node.Document;
                    }
                    var attrib = (node as XAttribute);
                    if (attrib != null)
                    {
                        removeChange.NextNode = attrib.NextAttribute;
                    }
                    else
                    {
                        removeChange.NextNode = (node as XNode).NextNode;
                    }
                    currentChange = removeChange;
                    break;
                case XObjectChange.Name:
                    var nameChange = new NodeNameChange(node, action);
                    if ((element = node as XElement) != null)
                    {
                        nameChange.OldName = element.Name;
                    }
                    else if ((pi = node as XProcessingInstruction) != null)
                    {
                        nameChange.OldName = XName.Get(pi.Target);
                    }
                    else
                    {
                        Debug.Assert(false, "The name of something changed that we're not handling here!");
                        throw new NotSupportedException();
                    }
                    currentChange = nameChange;
                    break;
                case XObjectChange.Value:
                    var valueChange = new NodeValueChange(node, action);
                    if ((element = node as XElement) != null)
                    {
                        valueChange.OldValue = element.Value;
                    }
                    else if ((attribute = node as XAttribute) != null)
                    {
                        valueChange.OldValue = attribute.Value;
                    }
                    else if ((text = node as XText) != null)
                    {
                        valueChange.OldValue = text.Value;
                        if (text.Parent != null)
                        {
                            valueChange.Parent = text.Parent;
                        }
                        else
                        {
                            valueChange.Parent = text.Document;
                        }
                    }
                    else if ((comment = node as XComment) != null)
                    {
                        valueChange.OldValue = comment.Value;
                    }
                    else if ((pi = node as XProcessingInstruction) != null)
                    {
                        valueChange.OldValue = pi.Data;
                    }
                    else
                    {
                        Debug.Assert(false, "The value of something changed that we're not handling here!");
                        throw new NotSupportedException();
                    }
                    currentChange = valueChange;
                    break;
            }
        }
 internal virtual NodeNameCommand CreateSetNameCommand(
     VanillaXmlModelProvider provider, NodeNameChange change)
 {
     return new NodeNameCommand(change);
 }