示例#1
0
        public View GetProperty(string propertyName, bool createImplicitly = true)
        {
            // this falls back to case insensitive matches if th property didn't exist.
            if (propertyName.Contains('.'))
            {
                return(GetChild(propertyName, createImplicitly)); // let that unroll the path.to.property
            }

            propertyName = ResolveAlias(propertyName);
            if (propertyName.StartsWith("::"))
            {
                return(RootView.GetChild(propertyName.Trim(':'), createImplicitly));
            }

            if (map.ContainsKey(propertyName))
            {
                return(map[propertyName]);
            }

            // cheat: let's see if there is a case insensitive version:
            var result = (map.Keys.Where(each => each.Equals(propertyName, StringComparison.InvariantCultureIgnoreCase)).Select(i => map[i])).FirstOrDefault();

            if (result != null)
            {
                return(result);
            }

            // let's add a placeholder node for it then.

            return(createImplicitly?  CreatePlaceholderView(propertyName) : null);
        }
示例#2
0
        internal View GetChild(Selector selector, bool createImplicity, Func <string, string> lastMinuteReplacementFunction, HashSet <string> history)
        {
            if (selector == null || selector.IsEmpty)
            {
                return(this);
            }

            if (string.IsNullOrEmpty(selector.Name) && selector.Parameter != null)
            {
                selector = new Selector("*", selector.Parameter, selector.SourceLocation, selector.AfterTheParameter);
            }

            selector = ResolveAlias(selector, history);

            if (selector.IsGlobal)
            {
                return(RootView.GetChild(selector.DeGlobaled, createImplicity, lastMinuteReplacementFunction, history));
            }

            if (selector.AfterTheParameter.Is())
            {
                return(GetChild(selector.WithoutAfterTheParameter, createImplicity, lastMinuteReplacementFunction, history).GetChild(selector.AfterSelector, createImplicity, lastMinuteReplacementFunction, history));
            }

            if (selector.IsCompound)
            {
                var name = selector.Prefix.Name;

                var resolved = ResolveAlias(name, history);
                if (resolved != name && resolved.IndexOfAny(new char[] { '.', '[', ']', ':' }) > -1)
                {
                    var result = GetProperty(resolved, createImplicity, lastMinuteReplacementFunction, history);
                    if (result != null)
                    {
                        return(result.GetChild(selector.Suffix, createImplicity, lastMinuteReplacementFunction, history));
                    }
                    return(null);
                }

                return(HasChild(name) ? GetProperty(name, createImplicity, lastMinuteReplacementFunction, history).GetChild(selector.Suffix, createImplicity, lastMinuteReplacementFunction, history) : (createImplicity ? CreatePlaceholderView(name).GetChild(selector.Suffix, createImplicity, lastMinuteReplacementFunction, history) : null));
            }

            if (selector.IsSpecialCase)
            {
                // this ensures a special case where a selector is resolving, but it has an empty auto-condition in it.
                // this should make sure that '*[].foo' is the same thing as 'foo'
                return(GetChild(selector.AfterSelector, createImplicity, lastMinuteReplacementFunction, history));
            }

            if (selector.HasParameter)
            {
                return(HasChild(selector.Name) ? GetProperty(selector.Name, createImplicity, lastMinuteReplacementFunction, history).GetElement(selector.Parameter, lastMinuteReplacementFunction) : (createImplicity ? CreatePlaceholderView(selector.Name).GetElement(selector.Parameter, lastMinuteReplacementFunction) : null));
            }

            return(GetProperty(selector.Name, createImplicity, lastMinuteReplacementFunction, history));
        }
示例#3
0
        internal View GetChild(Selector selector, bool createImplicity = true)
        {
            if (selector == null || selector.IsEmpty)
            {
                return(this);
            }

            if (string.IsNullOrEmpty(selector.Name) && selector.Parameter != null)
            {
                selector = new Selector("*", selector.Parameter, selector.SourceLocation, selector.AfterTheParameter);
            }

            selector = ResolveAlias(selector);

            if (selector.IsGlobal)
            {
                return(RootView.GetChild(selector.DeGlobaled, createImplicity));
            }

            if (selector.AfterTheParameter.Is())
            {
                return(GetChild(selector.WithoutAfterTheParameter, createImplicity).GetChild(selector.AfterSelector, createImplicity));
            }

            if (selector.IsCompound)
            {
                var name = selector.Prefix.Name;
                return(HasChild(name) ? GetProperty(name, createImplicity).GetChild(selector.Suffix, createImplicity) : (createImplicity ? CreatePlaceholderView(name).GetChild(selector.Suffix, createImplicity) : null));
            }

            if (selector.IsSpecialCase)
            {
                // this ensures a special case where a selector is resolving, but it has an empty auto-condition in it.
                // this should make sure that '*[].foo' is the same thing as 'foo'
                return(GetChild(selector.AfterSelector, createImplicity));
            }

            if (selector.HasParameter)
            {
                return(HasChild(selector.Name) ? GetProperty(selector.Name, createImplicity).GetElement(selector.Parameter) : (createImplicity ? CreatePlaceholderView(selector.Name).GetElement(selector.Parameter) : null));
            }

            return(GetProperty(selector.Name, createImplicity));
        }
示例#4
0
        public View GetProperty(string propertyName, bool createImplicitly = true, Func <string, string> lastMinuteReplacementFunction = null, HashSet <string> history = null)
        {
            history = history ?? new HashSet <string>();

            if (lastMinuteReplacementFunction != null)
            {
                propertyName = lastMinuteReplacementFunction(propertyName);
            }
            // if we have a dot, we have to navigate first
            if (propertyName.Contains('.'))
            {
                return(GetChild(propertyName, createImplicitly, lastMinuteReplacementFunction, history)); // let that unroll the path.to.property
            }

            propertyName = ResolveAlias(propertyName, history);

            // if we got a new name from an alias, we'd better check to see if we're still supposed to be here.
            if (propertyName.StartsWith("::"))
            {
                return(RootView.GetChild(propertyName.Trim(':'), createImplicitly, lastMinuteReplacementFunction, history));
            }

            if (propertyName.Contains('.'))
            {
                return(GetChild(propertyName, createImplicitly, lastMinuteReplacementFunction, history)); // let that unroll the path.to.property
            }

            if (map.ContainsKey(propertyName))
            {
                return(map[propertyName]);
            }

            // cheat: let's see if there is a case insensitive version:
            // var result = (map.Keys.Where(each => each.Equals(propertyName, StringComparison.InvariantCultureIgnoreCase)).Select(i => map[i])).FirstOrDefault();
            // if (result != null) {
            //     return result;
            // }

            // let's add a placeholder node for it then.

            return(createImplicitly?  CreatePlaceholderView(propertyName) : null);
        }