[Mono-dev] NUnit 2.2.6 Portability Bug

Jonathan Pryor jonpryor at vt.edu
Fri Jan 27 21:11:11 EST 2006


On Fri, 2006-01-27 at 12:25 -0800, Charlie Poole wrote:
> I have some code that can be modified to replace the functions I use, but
> before I re-invent the wheel, can anyone point to portable implementations
> of Windows PathCanonicalize and PathRelativePathTo? Better yet, does anyone
> want to contribute implementations? See PathUtils.cs for how we use these
> functions.

PathCanonicalize: System.IO.Path.GetFullPath() performs path
canonicalization.  At least Mono's version does...

PathRelativePathTo: this variation on your PathUtils.RelativePath works
for me (minimally tested):

	public static string RelativePath (string from, string to)
	{
		string[] _from = from.Split (Path.DirectorySeparatorChar);
		string[] _to   =   to.Split (Path.DirectorySeparatorChar);

		StringBuilder sb = new StringBuilder (from.Length + to.Length);

		int last_common, min = Math.Min (_from.Length, _to.Length);
		for (last_common = 0; last_common < min;  ++last_common) {
			if (!_from [last_common].Equals (_to [last_common]))
				break;
		}
		for (int i = last_common; i < _from.Length; ++i) {
			if (sb.Length > 0)
				sb.Append (Path.DirectorySeparatorChar);
			sb.Append ("..");
		}
		for (int i = last_common; i < _to.Length; ++i)
			sb.Append (Path.DirectorySeparatorChar).Append (_to [i]);

		return sb.ToString ();
	}

 - Jon





More information about the Mono-devel-list mailing list