public void nested_property_discovered() { var demo = new NestedProperties(); Structure.Start(demo, TestOptions <NestedProperties>("[]")); DiscoveredKeys.ShouldContainKey("nested/keystring"); }
/// <summary> /// Get a nested property from the <see cref="NestedProperties" /> dictionary /// </summary> /// <param name="key">The name of the nested property.</param> /// <param name="okIfNotExists"> /// True if it is OK if <paramref name="key" /> was not found in /// <see cref="NestedProperties" />. /// </param> /// <returns> /// The nested property found, or null if <paramref name="okIfNotExists" /> is true and <paramref name="key" /> /// was not found. /// </returns> public Data GetNestedProperty(string key, bool okIfNotExists) { if (!NestedProperties.ContainsKey(key)) { if (okIfNotExists) { return(null); } throw new ArgumentOutOfRangeException("key"); } return(NestedProperties[key]); }
private bool SetPropertyValue(string value, Queue <string> path) { var key = path.Dequeue(); if (path.Count == 0) { CheckSum = null; if (Properties == null) { Properties = new CaseInsensitiveDictionary <string>(); } Properties[key] = value; if (value != null) { return(false); } // Remove the value Properties.Remove(key); if (Properties.Count != 0) { return(false); } Properties = null; return(true); } var data = GetNestedProperty(key, true); if (data == null) { CheckSum = null; data = new Data(); NestedProperties[key] = data; } var remove = SetPropertyValue(value, path); if (!remove) { return(false); } NestedProperties.Remove(key); if (NestedProperties.Count != 0) { return(false); } NestedProperties = null; return(true); }
/// <summary> /// WebDav Property. /// </summary> /// <param name="property"></param> public DavProperty(XPathNavigator property) { if (property == null) { throw new ArgumentNullException("property", InternalFunctions.GetResourceString("ArgumentNullException", "Property")); } else if (property.NodeType != XPathNodeType.Element) { throw new ArgumentException(InternalFunctions.GetResourceString("XPathNavigatorElementArgumentException", "Property"), "property"); } base.Name = property.LocalName; base.Namespace = property.NamespaceURI; if (property.HasAttributes) { //TODO: Support element attributes //string _here = ""; //Add the attributes first // foreach (XmlAttribute _xmlAttribute in property.Attributes) // Attributes.Add(new DavPropertyAttribute(_xmlAttribute)); } if (property.MoveToFirstChild()) { if (property.NodeType == XPathNodeType.Element) { NestedProperties.Add(new DavProperty(property.Clone())); while (property.MoveToNext()) { if (property.NodeType == XPathNodeType.Element) { NestedProperties.Add(new DavProperty(property.Clone())); } } } else if (property.NodeType == XPathNodeType.Text) { base.Value = property.Value; property.MoveToParent(); } } }
private void AddThisDataObjectToMd5(ICryptoTransform md5, IEnumerable <Queue <string> > blackList) { var enumerable = blackList as IList <Queue <string> > ?? blackList.ToList(); var thisLevelBlackList = enumerable.Select(q => q.Peek()); if (Properties != null) { var netProperties = Properties .Where(p => !ReferenceEquals(p.Value, null) && !thisLevelBlackList.Contains(p.Key)) .OrderBy(p => p.Key); AddPropertiesToMd5(md5, netProperties); } if (NestedProperties == null) { return; } foreach (var nestedProperty in NestedProperties .Where(p => !ReferenceEquals(p.Value, null) && !thisLevelBlackList.Contains(p.Key)) .OrderBy(p => p.Key)) { var nestedBlackList = new List <Queue <string> >(); foreach (var queue in enumerable) { if (nestedProperty.Key != queue.Peek()) { continue; } var clone = new Queue <string>(queue); clone.Dequeue(); nestedBlackList.Add(clone); } nestedProperty.Value.AddThisDataObjectToMd5(md5, nestedBlackList); } }