示例#1
0
        // override object.Equals
        public override bool Equals(object obj)
        {
            //
            // See the full list of guidelines at
            //   http://go.microsoft.com/fwlink/?LinkID=85237
            // and also the guidance for operator== at
            //   http://go.microsoft.com/fwlink/?LinkId=85238
            //

            if (obj == null || GetType() != obj.GetType())
            {
                return(false);
            }

            FileTreeItem theItem = (FileTreeItem)obj;

            if ((theItem.Parent == null && Parent != null) ||
                (theItem.Parent != null && Parent == null))
            {
                return(false);
            }
            if (Parent != null && theItem.Parent != null && theItem.Parent.Equals(Parent) == false)
            {
                return(false);
            }
            if (theItem.Location.Equals(Location) == false)
            {
                return(false);
            }
            return(true);
        }
示例#2
0
        /// <summary>
        /// Gets the list of child elements of the path provided
        /// </summary>
        /// <param name="item">The parent item</param>
        /// <returns>The child list</returns>
        public IEnumerable <FileTreeItem> GetChildrenOf(FileTreeItem item)
        {
            IList <String> result = new List <String>();

            foreach (String aFile in _files)
            {
                if (aFile.StartsWith(item.Location))
                {
                    String child = item.Location;
                    int    i     = child.Length;
                    while (i < aFile.Length &&
                           aFile[i].Equals(Path.DirectorySeparatorChar) == false)
                    {
                        child += aFile[i];
                        i++;
                    }

                    //add the last separator char
                    if (i < aFile.Length)
                    {
                        child += aFile[i];
                    }

                    if (result.Contains(child) == false)
                    {
                        result.Add(child);
                    }
                }
            }

            if (result.Count == 1 &&
                result[0].Equals(item.Location))
            {
                return(new List <FileTreeItem>());
            }
            else
            {
                IList <FileTreeItem> resultList = new List <FileTreeItem>();
                foreach (String aFile in result)
                {
                    resultList.Add(new FileTreeItem(item, aFile));
                }
                return(resultList);
            }
        }
示例#3
0
 /// <summary>
 /// Create a new instance of this class
 /// </summary>
 /// <param name="parent">The parent of the item</param>
 /// <param name="location">The full location including the root</param>
 public FileTreeItem(FileTreeItem parent, String location)
 {
     Parent   = parent;
     Location = location;
 }