GetContextForPath() private method

private GetContextForPath ( Queue elements ) : ContextObject
elements Queue
return ContextObject
Example #1
0
        private ContextObject GetContextForPath(Queue <String> elements)
        {
            var retval = this;

            if (elements.Any())
            {
                var element = elements.Dequeue();
                if (element.StartsWith(".."))
                {
                    if (Parent != null)
                    {
                        retval = Parent.GetContextForPath(elements);
                    }
                    else
                    {
                        //calling "../" too much may be "ok" in that if we're at root,
                        //we may just stop recursion and traverse down the path.
                        retval = GetContextForPath(elements);
                    }
                }
                //TODO: handle array accessors and maybe "special" keys.
                else
                {
                    //ALWAYS return the context, even if the value is null.
                    var innerContext = new ContextObject();
                    innerContext.Key    = element;
                    innerContext.Parent = this;
                    var ctx = this.Value as IDictionary <string, object>;
                    if (ctx != null)
                    {
                        object o;
                        ctx.TryGetValue(element, out o);
                        innerContext.Value = o;
                    }
                    retval = innerContext.GetContextForPath(elements);
                }
            }
            return(retval);
        }
Example #2
0
 private ContextObject GetContextForPath(Queue<String> elements)
 {
     var retval = this;
     if (elements.Any())
     {
         var element = elements.Dequeue();
         if (element.StartsWith(".."))
         {
             if (Parent != null)
             {
                 retval = Parent.GetContextForPath(elements);
             }
             else
             {
                 //calling "../" too much may be "ok" in that if we're at root,
                 //we may just stop recursion and traverse down the path.
                 retval = GetContextForPath(elements);
             }
         }
         //TODO: handle array accessors and maybe "special" keys.
         else
         {
             //ALWAYS return the context, even if the value is null.
             var innerContext = new ContextObject();
             innerContext.Key = element;
             innerContext.Parent = this;
             var ctx = this.Value as IDictionary<string, object>;
             if (ctx != null)
             {
                 object o;
                 ctx.TryGetValue(element, out o);
                 innerContext.Value = o;
             }
             retval = innerContext.GetContextForPath(elements);
         }
     }
     return retval;
 }