// Deal with duplicate keys by appending a simple number to them.
        // Should be called AFTER PopulateFromXml() has done its work.
        protected void SetAppropriateKey(CanonicalItem item)
        {
            string origKey = item.Key;
            int    extra   = 0;

            while (byKey.ContainsKey(item.Key))
            {
                extra++;
                item.Key = origKey + extra.ToString();
            }
        }
        protected void UpdateDictsFromItem(CanonicalItem item)
        {
            Guid g = Guid.Empty;

            if (Guid.TryParse(item.GuidStr, out g))
            {
                // Update either both dicts, or neither.
                byGuid[g] = item;
                SetAppropriateKey(item);
                byKey[item.Key] = item;
            }
            foreach (CanonicalItem subitem in item.Subitems)
            {
                UpdateDictsFromItem(subitem);
            }
        }
 public bool TryGetByKey(string key, out CanonicalItem result)
 {
     result = ByKeyOrNull(key);
     return(result != null);
 }
 public bool TryGetByGuid(Guid g, out CanonicalItem result)
 {
     result = ByGuidOrNull(g);
     return(result != null);
 }
Exemple #5
0
 public void AppendChild(CanonicalItem child)
 {
     Subitems.Add(child);
     child.Parent = this;
 }