深入研究源代码可以发现实际实现Path.IsPathRooted
是这样的:
public static bool IsPathRooted(string path)
{
if (path != null)
{
Path.CheckInvalidPathChars(path);
int length = path.Length;
if ((length >= 1 && (path[0] == Path.DirectorySeparatorChar || path[0] == Path.AltDirectorySeparatorChar))
|| (length >= 2 && path[1] == Path.VolumeSeparatorChar))
{
return true;
}
}
return false;
}
Now it becomes evident how to adjust it to suit your needs - you can define a new method and slightly change the conditions (and maybe refactor them a little - they do not look very good):
if ((length >= 1 && ((path[0] == Path.DirectorySeparatorChar && path[1] == Path.DirectorySeparatorChar) || path[0] == Path.AltDirectorySeparatorChar))
|| (length >= 3 && path[1] == Path.VolumeSeparatorChar && path[2] == Path.DirectorySeparatorChar))