public override bool Equals(object obj)
        {
            // If parameter cannot be cast to Point return false.
            SubPathInfo p = obj as SubPathInfo;

            if (p == null)
            {
                string pathString = obj as string;
                if (pathString == null)
                {
                    return(false);
                }
                try
                {
                    p = SubPathInfo.Parse(pathString);
                }
                catch (Exception e)
                {
                    return(false);
                }
            }

            // Return true if the fields match:
            //todo: make case sensitivity depend on platform?
            // ie windows file system is not case sensitive..

            return((Directory.Equals(p.Directory, StringComparison.OrdinalIgnoreCase)) &&
                   (Name.Equals(p.Name, StringComparison.OrdinalIgnoreCase)));
        }
 public bool IsMatch(SubPathInfo subPath)
 {
     if (subPath.IsPattern)
     {
         return(this.Like(subPath.ToString()));
     }
     if (string.IsNullOrEmpty(subPath.Name) && IsInSameDirectory(subPath))
     {
         return(true);
     }
     return(this.Equals(subPath));
 }
        public static SubPathInfo Parse(string subpath)
        {
            if (string.IsNullOrWhiteSpace(subpath))
            {
                return(new SubPathInfo(string.Empty, string.Empty));
                // throw new ArgumentException("subpath");
            }

            var builder = new StringBuilder(subpath.Length);

            var indexOfLastSeperator = subpath.LastIndexOf('/');

            if (indexOfLastSeperator != -1)
            {
                // has directory portion.
                for (int i = 0; i <= indexOfLastSeperator; i++)
                {
                    var currentChar = subpath[i];
                    if (currentChar == '/')
                    {
                        if (i == 0 || i == indexOfLastSeperator) // omit a starting and trailing slash (/)
                        {
                            continue;
                        }
                    }

                    builder.Append(currentChar);
                }
            }

            var directory = builder.ToString();

            builder.Clear();

            // now append Name portion
            if (subpath.Length > indexOfLastSeperator + 1)
            {
                for (int c = indexOfLastSeperator + 1; c < subpath.Length; c++)
                {
                    var currentChar = subpath[c];
                    builder.Append(currentChar);
                }
            }

            var name    = builder.ToString();
            var subPath = new SubPathInfo(directory, name);

            return(subPath);
        }
        public bool IsInSameDirectory(SubPathInfo directory)
        {
            var match = directory.Directory == Directory;

            return(match);
        }