/// <summary> /// Returns whether the current PathInfo is a valid parent of the child path info /// passed as argument. /// </summary> /// <param name = "child">The path info to verify</param> /// <returns>Whether it is true that the current path info is a parent of child.</returns> /// <exception cref = "NotSupportedException">If this instance of path info and child aren't rooted.</exception> public bool IsParentOf(PathInfo child) { Contract.Requires(child != null); if (Root == string.Empty || child.Root == string.Empty) { throw new NotSupportedException("Non-rooted paths are not supported."); } // TODO: Normalize Path var OK = child.FolderAndFiles.StartsWith(FolderAndFiles); switch (Type) { case PathType.Device: OK &= child.DeviceName.Equals(DeviceName, StringComparison.InvariantCultureIgnoreCase); break; case PathType.Server: OK &= child.ServerName.Equals(ServerName, StringComparison.InvariantCultureIgnoreCase); break; case PathType.IPv4: OK &= child.IPv4.Equals(IPv4); break; case PathType.IPv6: OK &= child.IPv6.Equals(IPv6); break; case PathType.Relative: throw new NotSupportedException("Since root isn't empty we should never get relative paths."); case PathType.Drive: OK &= DriveLetter.ToLowerInvariant() == child.DriveLetter.ToLowerInvariant(); break; } return(OK); }
/// <summary> /// Returns whether the current PathInfo is a valid parent of the child path info /// passed as argument. /// </summary> /// <param name="child">The path info to verify</param> /// <returns>Whether it is true that the current path info is a parent of child.</returns> /// <exception cref="NotSupportedException">If this instance of path info and child aren't rooted.</exception> public bool IsParentOf(PathInfo child) { if (Root == string.Empty || child.Root == string.Empty) { throw new NotSupportedException("Non-rooted paths are not supported."); } var OK = child.FolderAndFiles.StartsWith(FolderAndFiles); switch (Type) { case PathType.Device: OK &= child.DeviceName.ToLowerInvariant() == DeviceName.ToLowerInvariant(); break; case PathType.Server: OK &= child.ServerName.ToLowerInvariant() == ServerName.ToLowerInvariant(); break; case PathType.IPv4: OK &= IPAddress.Parse(child.IPv4).Equals(IPAddress.Parse(IPv4)); break; case PathType.IPv6: OK &= (IPAddress.Parse(child.IPv6).Equals(IPAddress.Parse(IPv6))); break; case PathType.Relative: throw new InvalidOperationException("Since root isn't empty we should never get relative paths."); case PathType.Drive: OK &= DriveLetter.ToLowerInvariant() == child.DriveLetter.ToLowerInvariant(); break; } return(OK); }