コード例 #1
0
ファイル: NamespaceCache.cs プロジェクト: jmorgannz/jint
        protected static NamespaceCacheElement AppendNamespaceElement(NamespaceCacheElement ncParent, string name)
        {
            if (ncParent == null)
            {
                throw new ArgumentException("Invalid argument: parent");
            }
            if (String.IsNullOrWhiteSpace(name) || name.Contains("."))
            {
                throw new ArgumentException("Invalid argument: name");
            }

            NamespaceCacheElement ncChild = findDescendent(ncParent, name, false);

            if (ncChild == null)
            {
                ncChild = new NamespaceCacheElement(ncParent, name);
                if (ncParent._ncChildren == null)
                {
                    ncParent._ncChildren = new Generic.Dictionary <String, NamespaceCacheElement>(StringComparer.OrdinalIgnoreCase);
                }
                ncParent._ncChildren[name] = ncChild;
            }

            return(ncChild);
        }
コード例 #2
0
ファイル: NamespaceCache.cs プロジェクト: jmorgannz/jint
        protected static NamespaceCacheElement findDescendent(NamespaceCacheElement ncElem, String ns, bool throwOnNamespaceNotFound)
        {
            if (String.IsNullOrWhiteSpace(ns))
            {
                throw new ArgumentException("Invalid argument: namespace");
            }

            String[] nsParts = ns.Split('.');

            for (int i = 0; i < nsParts.Length; i++)
            {
                String nsPart = nsParts[i];

                if (ncElem._ncChildren == null || !ncElem._ncChildren.ContainsKey(nsPart))
                {
                    ncElem = null;
                    break;
                }

                ncElem = ncElem._ncChildren[nsPart];
            }

            if (throwOnNamespaceNotFound && ncElem == null)
            {
                throw new System.Collections.Generic.KeyNotFoundException();
            }

            return(ncElem);
        }
コード例 #3
0
ファイル: NamespaceCache.cs プロジェクト: jmorgannz/jint
        private static void populate(NamespaceCacheRoot ncRoot, String ns)
        {
            String[] nsParts = ns.Split('.');

            NamespaceCacheElement ncElem = ncRoot;

            foreach (String nsPart in nsParts)
            {
                ncElem = AppendNamespaceElement(ncElem, nsPart);
            }
        }
コード例 #4
0
ファイル: NamespaceCache.cs プロジェクト: jmorgannz/jint
        protected static String assembleAbsoluleName(NamespaceCacheElement ncElem)
        {
            if (ncElem is NamespaceCacheRoot)
            {
                return("[Global]");
            }
            NamespaceCacheElement[] ncAncestors = enumerateAncestors(ncElem, true);

            if (ncAncestors.First() is NamespaceCacheRoot)
            {
                return(String.Join(".", ncAncestors.Skip(1).Select(x => x.Name).ToArray()));
            }

            throw new Exception("Orphan namespace, cannot resolve full path");
        }
コード例 #5
0
ファイル: NamespaceCache.cs プロジェクト: jmorgannz/jint
        protected static NamespaceCacheRoot traverseToRoot(NamespaceCacheElement ncElem)
        {
            if (ncElem is NamespaceCacheRoot)
            {
                return((NamespaceCacheRoot)ncElem);
            }

            NamespaceCacheElement ncOldestAncestor = enumerateAncestors(ncElem).DefaultIfEmpty(null).First();

            if (ncOldestAncestor == null || !(ncOldestAncestor is NamespaceCacheRoot))
            {
                return(null);
            }

            return((NamespaceCacheRoot)ncOldestAncestor);
        }
コード例 #6
0
ファイル: NamespaceCache.cs プロジェクト: jmorgannz/jint
        protected static NamespaceCacheElement[] enumerateAncestors(NamespaceCacheElement ncElem, bool includeSelf)
        {
            Generic.List <NamespaceCacheElement> ncAncestors = new Generic.List <NamespaceCacheElement>();

            if (includeSelf)
            {
                ncAncestors.Insert(0, ncElem);
            }

            while (ncElem.Parent != null)
            {
                ncElem = ncElem.Parent;
                ncAncestors.Insert(0, ncElem);
            }

            return(ncAncestors.ToArray());
        }
コード例 #7
0
ファイル: NamespaceCache.cs プロジェクト: jmorgannz/jint
 protected static NamespaceCacheElement[] enumerateAncestors(NamespaceCacheElement ncElem)
 {
     return(enumerateAncestors(ncElem, false));
 }
コード例 #8
0
ファイル: NamespaceCache.cs プロジェクト: jmorgannz/jint
 // Methods
 public bool ContainsNamespace(NamespaceCacheElement ncElem)
 {
     return(_ncChildren != null && _ncChildren.ContainsKey(ncElem.Name));
 }
コード例 #9
0
ファイル: NamespaceCache.cs プロジェクト: jmorgannz/jint
        // Gah, why doesn't C# support indexed properties yet >:(

        /*public NamespaceCacheElement Children[String ns] {
         *  get { return _children[ns]; }
         * }*/

        // Constructor (public construction not allowed)
        protected NamespaceCacheElement(NamespaceCacheElement parent, String name)
        {
            _parent = parent;
            _name   = name;
        }
コード例 #10
0
ファイル: NamespaceCache.cs プロジェクト: jmorgannz/jint
 protected static NamespaceCacheElement findDescendent(NamespaceCacheElement ncElem, String ns)
 {
     return(findDescendent(ncElem, ns, false));
 }