private static bool MoveToChildNode(XPathNavigator navigator, NamespaceAndName childNode) { if (navigator == null) { throw new ArgumentNullException("navigator"); } if (childNode == null) { throw new ArgumentNullException("childNode"); } if (childNode.Name == null) { throw new NullReferenceException("childNode.Name"); } if (childNode.Namespace == null) { throw new NullReferenceException("childNode.Namespace"); } var previousNavigator = navigator.Clone(); navigator.MoveToChild(childNode.Name, childNode.Namespace); if (navigator.IsSamePosition(previousNavigator)) { return(false); } return(true); }
public static XmlDocument DeleteXmlAttribute(string filePath, string @namespace, IEnumerable <string> parentNodeNames, string attributeName, bool saveOnCompletion = true, XmlDocument alteredDocument = null) { if (filePath == null) { throw new ArgumentNullException("filePath"); } if (@namespace == null) { throw new ArgumentNullException("namespace"); } if (parentNodeNames == null) { throw new ArgumentNullException("parentNodeNames"); } if (attributeName == null) { throw new ArgumentNullException("attributeName"); } var parentNodes = parentNodeNames .Where(parentNodeName => parentNodeName != null) .Select(parentNodeName => new NamespaceAndName { Namespace = @namespace, Name = parentNodeName }); var attribute = new NamespaceAndName { Name = attributeName }; return(DeleteXmlAttribute(filePath, parentNodes, attribute, saveOnCompletion, alteredDocument)); }
private static void MoveToOrCreateChildNode(XPathNavigator navigator, NamespaceAndName childNode) { if (navigator == null) { throw new ArgumentNullException("navigator"); } if (childNode == null) { throw new ArgumentNullException("childNode"); } if (childNode.Name == null) { throw new NullReferenceException("childNode.Name"); } if (childNode.Namespace == null) { throw new NullReferenceException("childNode.Namespace"); } if (MoveToChildNode(navigator, childNode)) { return; } navigator.AppendChildElement(string.Empty, childNode.Name, childNode.Namespace, string.Empty); navigator.MoveToChild(childNode.Name, childNode.Namespace); }
private static void SetOrCreateAttribute(XPathNavigator navigator, NamespaceAndName attribute, string value) { if (navigator == null) { throw new ArgumentNullException("navigator"); } if (attribute == null) { throw new ArgumentNullException("attribute"); } if (value == null) { throw new ArgumentNullException("value"); } var localNavigator = navigator.Clone(); if (localNavigator.GetAttribute(attribute.Name, attribute.Namespace) != string.Empty) { localNavigator.MoveToAttribute(attribute.Name, attribute.Namespace); localNavigator.SetValue(value); } else { localNavigator.CreateAttribute(string.Empty, attribute.Name, attribute.Namespace, value); } }
public static XmlDocument AddXmlNode(string filePath, string @namespace, IEnumerable <string> parentNodeNames, string nodeName, string value, bool saveOnCompletion = true, XmlDocument alteredDocument = null) { if (filePath == null) { throw new ArgumentNullException("filePath"); } if (@namespace == null) { throw new ArgumentNullException("namespace"); } if (parentNodeNames == null) { throw new ArgumentNullException("parentNodeNames"); } if (nodeName == null) { throw new ArgumentNullException("nodeName"); } if (value == null) { throw new ArgumentNullException("value"); } var parentNodes = parentNodeNames .Where(parentNodeName => parentNodeName != null) .Select(parentNodeName => new NamespaceAndName { Namespace = @namespace, Name = parentNodeName }); var leafNode = new NamespaceAndName { Namespace = @namespace, Name = nodeName }; return(AddXmlNode(filePath, parentNodes, leafNode, value, saveOnCompletion, alteredDocument)); }
public string GetTypeName(CsClass str, NamespaceAndName valueEnumTypeName) { if (FixedType != null) { return(str.GetTypeName(FixedType)); } return(str.GetTypeName(valueEnumTypeName)); }
static void enforceNamedArgName(NamespaceAndName name, CustomAttributeValue <CustomAttrType> args, string expected, int index) { string?actual = args.NamedArguments[index].Name; assertData(actual == expected, string.Format( "expected attribute '{0}' to have named argument at index {1} to be named '{2}' but got '{3}'", name, index, expected, actual)); }
static void enforceAttrNamedArgCount(NamespaceAndName name, CustomAttributeValue <CustomAttrType> args, uint expected) { if (args.NamedArguments.Length != expected) { throw new InvalidDataException(string.Format( "expected attribute '{0}' to have {1} named arguments but got {2}", name.name, expected, args.NamedArguments.Length)); } }
public static string GetTypeName(this ITypeNameResolver res, NamespaceAndName typeName) { if (res is INamespaceContainer container) { if (container.IsKnownNamespace(typeName.Namespace)) { return(typeName.Name); } } return(typeName.FullName); }
public PropInfo GetPropertyTypeName(OptionValueProcessorKind kind, ITypeNameResolver res, NamespaceAndName enumTypeName) { var v = ValueType.FixedType; string elementName; if (v != null) { switch (kind) { case OptionValueProcessorKind.List: case OptionValueProcessorKind.Dictionary: elementName = res.GetTypeName(v); break; case OptionValueProcessorKind.SingleValue: if (v.IsValueType) { v = typeof(Nullable <>).MakeGenericType(v); } elementName = res.GetTypeName(v); break; default: throw new ArgumentOutOfRangeException(nameof(kind), kind, null); } } else { var suffix = kind == OptionValueProcessorKind.SingleValue ? "?" : ";"; elementName = res.GetTypeName(enumTypeName) + suffix; } var tqq = new PropInfo(elementName); switch (kind) { case OptionValueProcessorKind.Dictionary: return(tqq.MakeDict(res)); case OptionValueProcessorKind.SingleValue: return(tqq); case OptionValueProcessorKind.List: return(tqq.MakeList(res)); default: throw new ArgumentOutOfRangeException(nameof(kind), kind, null); } }
public static XmlDocument DeleteXmlNode(string filePath, string @namespace, IEnumerable <string> parentNodeNames, string nodeName, bool saveOnCompletion = true, XmlDocument alteredDocument = null) { var document = alteredDocument ?? new XmlDocument(); if (alteredDocument == null) { document.Load(filePath); } var navigator = document.CreateNavigator(); var parentNodes = parentNodeNames .Where(parentNodeName => parentNodeName != null) .Select(parentNodeName => new NamespaceAndName { Namespace = @namespace, Name = parentNodeName }); var leafNode = new NamespaceAndName { Namespace = @namespace, Name = nodeName }; foreach (var parentNode in parentNodes) { if (parentNode == null) { continue; } if (!MoveToChildNode(navigator, parentNode)) { return(new XmlDocument()); } } if (!MoveToChildNode(navigator, leafNode)) { return(new XmlDocument()); } navigator.DeleteSelf(); if (saveOnCompletion) { document.Save(filePath); } return(document); }
private static void SetOrCreateNode(XPathNavigator navigator, NamespaceAndName node, string value) { if (navigator == null) { throw new ArgumentNullException("navigator"); } if (node == null) { throw new ArgumentNullException("node"); } if (value == null) { throw new ArgumentNullException("value"); } MoveToOrCreateChildNode(navigator, node); navigator.SetValue(value); }
private static XmlDocument AddXmlNode(string filePath, IEnumerable <NamespaceAndName> parentNodes, NamespaceAndName node, string nodeValue, string attributeName, string attributeValue, bool saveOnCompletion = true, XmlDocument alteredDocument = null) { if (filePath == null) { throw new ArgumentNullException("filePath"); } if (parentNodes == null) { throw new ArgumentNullException("parentNodes"); } if (node == null) { throw new ArgumentNullException("node"); } if (nodeValue == null) { throw new ArgumentNullException("nodeValue"); } if (attributeName == null) { throw new ArgumentNullException("attributeName"); } if (attributeValue == null) { throw new ArgumentNullException("attributeValue"); } var document = alteredDocument ?? new XmlDocument(); if (alteredDocument == null) { document.Load(filePath); } var navigator = document.CreateNavigator(); parentNodes .Where(parentNode => parentNode != null) .ToList() .ForEach(parentNode => MoveToOrCreateChildNode(navigator, parentNode)); //relace the below with a way to add a single atttrib to thhe node....S var childDoc = new XmlDocument(); var childElement = childDoc.CreateElement(node.Name); childElement.Attributes.Append(childDoc.CreateAttribute(attributeName)); childElement.Attributes[attributeName].Value = attributeValue; childDoc.AppendChild(childElement); var childNav = childDoc.CreateNavigator(); navigator.AppendChild(childDoc.InnerXml); if (saveOnCompletion) { document.Save(filePath); } return(document); }
private static XmlDocument AddXmlNode(string filePath, IEnumerable <NamespaceAndName> parentNodes, NamespaceAndName node, string value, bool saveOnCompletion = true, XmlDocument alteredDocument = null) { if (filePath == null) { throw new ArgumentNullException("filePath"); } if (parentNodes == null) { throw new ArgumentNullException("parentNodes"); } if (node == null) { throw new ArgumentNullException("node"); } if (value == null) { throw new ArgumentNullException("value"); } var document = alteredDocument ?? new XmlDocument(); if (alteredDocument == null) { document.Load(filePath); } var navigator = document.CreateNavigator(); parentNodes .Where(parentNode => parentNode != null) .ToList() .ForEach(parentNode => MoveToOrCreateChildNode(navigator, parentNode)); navigator.AppendChildElement(string.Empty, node.Name, node.Namespace, value); if (saveOnCompletion) { document.Save(filePath); } return(document); }
private static XmlDocument DeleteXmlAttribute(string filePath, IEnumerable <NamespaceAndName> parentNodes, NamespaceAndName attribute, bool saveOnCompletion = true, XmlDocument alteredDocument = null) { if (filePath == null) { throw new ArgumentNullException("filePath"); } if (parentNodes == null) { throw new ArgumentNullException("parentNodes"); } if (attribute == null) { throw new ArgumentNullException("attribute"); } var document = alteredDocument ?? new XmlDocument(); if (alteredDocument == null) { document.Load(filePath); } var navigator = document.CreateNavigator(); parentNodes .Where(parentNode => parentNode != null) .ForEachNow(parentNode => MoveToOrCreateChildNode(navigator, parentNode)); //don't save if nothing was done. if (navigator.GetAttribute(attribute.Name, attribute.Namespace) != string.Empty) { navigator.MoveToAttribute(attribute.Name, attribute.Namespace); navigator.DeleteSelf(); if (saveOnCompletion) { document.Save(filePath); } } return(document); }