コード例 #1
0
ファイル: DocumentPath.cs プロジェクト: carlhuth/GenXSource
        /// <summary>
        /// Get the absolute path of the node <code>node</code> starting from the root.
        /// </summary>
        /// <param name="node">The node for which the path is retrieved.</param>
        /// <returns>The absolute path of the node. The first element is a "/" to mark this as absolute path.</returns>
        public static DocumentPath GetAbsolutePath(IDocumentNode node)
        {
            DocumentPath path = GetPath(node, int.MaxValue);

            path.IsAbsolutePath = true;
            return(path);
        }
コード例 #2
0
ファイル: DocumentPath.cs プロジェクト: carlhuth/GenXSource
 public DocumentPath(DocumentPath from)
 {
     this._IsAbsolutePath = from._IsAbsolutePath;
     foreach (string s in from)
     {
         Add(s);
     }
 }
コード例 #3
0
ファイル: DocumentPath.cs プロジェクト: carlhuth/GenXSource
        /// <summary>
        /// Resolves the path by first using startnode as starting point. If that failed, try using documentRoot as starting point.
        /// </summary>
        /// <param name="path">The path to resolve.</param>
        /// <param name="startnode">The node object which is considered as the starting point of the path.</param>
        /// <param name="documentRoot">An alternative node which is used as starting point of the path if the first try failed.</param>
        /// <returns>The resolved object. If the resolving process failed, the return value is null.</returns>
        public static object GetObject(DocumentPath path, object startnode, object documentRoot)
        {
            object retval = GetObject(path, startnode);

            if (null == retval && null != documentRoot)
            {
                retval = GetObject(path, documentRoot);
            }

            return(retval);
        }
コード例 #4
0
ファイル: DocumentPath.cs プロジェクト: carlhuth/GenXSource
            public void Serialize(object obj, Altaxo.Serialization.Xml.IXmlSerializationInfo info)
            {
                DocumentPath s = (DocumentPath)obj;

                info.AddValue("IsAbsolute", s._IsAbsolutePath);

                info.CreateArray("Path", s.Count);
                for (int i = 0; i < s.Count; i++)
                {
                    info.AddValue("e", s[i]);
                }
                info.CommitArray();
            }
コード例 #5
0
ファイル: DocumentPath.cs プロジェクト: carlhuth/GenXSource
            public object Deserialize(object o, Altaxo.Serialization.Xml.IXmlDeserializationInfo info, object parent)
            {
                DocumentPath s = null != o ? (DocumentPath)o : new DocumentPath();


                s._IsAbsolutePath = info.GetBoolean("IsAbsolute");

                int count = info.OpenArray();

                for (int i = 0; i < count; i++)
                {
                    s.Add(info.GetString());
                }
                info.CloseArray(count);

                return(s);
            }
コード例 #6
0
ファイル: DocumentPath.cs プロジェクト: carlhuth/GenXSource
        /// <summary>
        /// Get the absolute path of the node <code>node</code> starting either from the root, or from the object in the depth
        /// <code>maxDepth</code>, whatever is reached first.
        /// </summary>
        /// <param name="node">The node for which the path is to be retrieved.</param>
        /// <param name="maxDepth">The maximal hierarchie depth (the maximal number of path elements returned).</param>
        /// <returns>The path from the root or from the node in the depth <code>maxDepth</code>, whatever is reached first. The path is <b>not</b> prepended
        /// by a "/".
        /// </returns>
        public static DocumentPath GetPath(IDocumentNode node, int maxDepth)
        {
            DocumentPath path = new DocumentPath();

            int    depth = 0;
            object root  = node;

            while (root != null && root is IDocumentNode)
            {
                if (depth >= maxDepth)
                {
                    break;
                }

                string name = ((IDocumentNode)root).Name;
                path.Insert(0, name);
                root = ((IDocumentNode)root).ParentObject;
                ++depth;
            }

            return(path);
        }
コード例 #7
0
ファイル: DocumentPath.cs プロジェクト: carlhuth/GenXSource
        public static object GetObject(DocumentPath path, object startnode)
        {
            object node = startnode;

            if (path.IsAbsolutePath && node is IDocumentNode)
            {
                node = GetRootNode((IDocumentNode)node);
            }

            for (int i = 0; i < path.Count; i++)
            {
                if (path[i] == "..")
                {
                    if (node is Main.IDocumentNode)
                    {
                        node = ((Main.IDocumentNode)node).ParentObject;
                    }
                    else
                    {
                        return(null);
                    }
                }
                else
                {
                    if (node is Main.INamedObjectCollection)
                    {
                        node = ((Main.INamedObjectCollection)node).GetChildObjectNamed(path[i]);
                    }
                    else
                    {
                        return(null);
                    }
                }
            } // end for
            return(node);
        }