示例#1
0
 public void SubRef4()
 {
     NodeRef nr = new NodeRef("/this/is/a/path");
     NodeRef sr = new NodeRef("/not/a/path");
     Assert.AreEqual("/not/a/path", nr.GetSubRef(sr).Path);
 }
示例#2
0
 public void SubPluses()
 {
     NodeRef nr = new NodeRef("/Test +1/A");
     NodeRef nr2 = new NodeRef("/Test +1");
     NodeRef nr3 = nr2.GetSubRef(nr);
     Assert.AreEqual("/A", nr3.ToString());
 }
示例#3
0
 public void SubRef2()
 {
     NodeRef nr = new NodeRef("/this/is");
     NodeRef sr = new NodeRef("/this/is");
     Assert.AreEqual("/", nr.GetSubRef(sr).Path);
 }
        /// <summary>
        /// Returns an attribute tree object that represents the path. If
        /// the second parameter is true, then it automatically creates it
        /// and any parent objects above it as needed.
        ///
        /// This does not handle "/" path which means the current
        /// one. Instead, you should retrieve it from the
        /// AttributeTree["/"].
        /// </summary>
        public AttributeTree this[NodeRef nref, bool create]
        {
            get
            {
                // Throw exceptions for null
                if (nref == null)
                    throw new UtilityException("Cannot retrieve a null node");

                // If we have a zero-length path ("/"), then we mean this one,
                // so ignore it.
                if (nref.Count == 0)
                    return null;

                // Grab the first element
                string first = "/" + nref[0];
                NodeRef firstRef = new NodeRef(first);

                // Check for it
                AttributeTree at = (AttributeTree) base.BaseGet(first);

                if (at == null && !create)
                {
                    // We can't find it and we can't create it
                    return null;
                }
                else if (at == null)
                {
                    // Create it
                    at = baseTree.CreateClone();
                    at.OnCreatedAsChild(firstRef, baseTree);
                    Add(first, at);
                }

                // Return it down the path
                NodeRef nr = firstRef.GetSubRef(nref);
                return at[nr, create];
            }
        }