我正在寻找一种干净的方式来将相对基础Uri与另一条相对路径相结合.我试过以下,但Uri(Uri, string)并UriBuilder(Uri)要求绝对URI(抛出InvalidOperationException异常:不支持该操作相对URI).
// where Settings.Default.ImagesPath is "~/path/to/images"
// attempt 1
_imagePath = new Uri(Settings.Default.ImagesPath, image);
// attempt 2
UriBuilder uriBuilder = new UriBuilder(Settings.Default.ImagesPath);
uriBuilder.Path += image;
_imagePath = uriBuilder.Uri;
Run Code Online (Sandbox Code Playgroud)
我不想做任何丑陋的字符串操作,以确保基本路径以尾部斜杠结束等.