如果`System.IO.Path`是混凝土?混凝土、System、IO、Path

由网友(再见、再也不见)分享简介:成员类如 Path.Combine 缺一不可。它们带来了巨大的,干净的,正确的code。不幸的是,如果你使用它像在C ++ preprocessor管理标题的路径,你很快就会意识到,它显示了在探查超过预期。为什么呢?Members of the Path class like Path.Combine are ind...

成员类如 Path.Combine 缺一不可。它们带来了巨大的,干净的,正确的code。不幸的是,如果你使用它像在C ++ preprocessor管理标题的路径,你很快就会意识到,它显示了在探查超过预期。为什么呢?

Members of the Path class like Path.Combine are indispensable. They lead to great, clean, correct code. Unfortunately, if you use it for something like managing header paths in a C++ preprocessor, you'll quickly realize that it's showing up more than expected in the profiler. Why?

异常:ArgumentException的:路径1 或路径2 的包含一个定义的无效字符或多个 GetInvalidPathChars

Exceptions: ArgumentException: path1 or path2 contain one or more of the invalid characters defined in GetInvalidPathChars.

即使不检查,结合命令为O(n)(因为它具有复制的字符串的内容)。然而,这是不检查任何 GetInvalidPathChars 的40名成员的存在〜便宜得多。

Even without the check, the combine command is O(n) (since it has to copy the string contents). However, that is much less expensive than checking for the existence of any of GetInvalidPathChars' ~40 members.

我相信路径类应该是一个不可变的类型包含已知不包含任何无效字符的字符串。应提供有关字符串运行静态成员(如存在至今)和同一组增加了对工作路径对象。进行此更改在.NET Framework:

I believe that the Path class should be an immutable type that contains a string known to not contain any invalid characters. Static members should be provided for operating on string (as exists now) and an identical set added for working on Path objects. Making this change in the .NET Framework:

是不是一个重大更改(改变静态类为混凝土密封型的非换) 在显着提高了几个最佳实践操作的性能

意见?

推荐答案

Uri类可以提供之类的功能,如果你不介意的文件://语法。我认为,净prefers使用Uri类的呢,因为这可以让资源不仅仅是本地文件等的定位,虽然这确实需要在方案方面额外的工作来支持这一点。

The Uri class can provide that sort of functionality if you don't mind the file:// syntax. I think .Net prefers the use of the Uri class anyway since that can allow locating of resources other than just local files, although this does require extra work on the program side to support that.

阅读全文

相关推荐

最新文章