C#StreamReader(字符串路径) - 路径是否可以以某种方式再次访问?

时间:2016-11-26 11:12:14

标签: c# streamreader

我是StreamReader的实现。

internal class MyStreamReader : StreamReader
{
    public MyStreamReader (string path) : base(path)
    {
    }

参数是文件的路径。

我想抛出异常并在其消息中包含完整的文件名。我当然知道我可以很容易地将它保存在我自己的班级中,例如" _path"但我想确保我不做任何多余的事情。我能以某种方式访问​​"路径"争论再次?

编辑,因为似乎有些混乱:

throw new FileLoadException($"Corrupt source file! File '{ // I need something to represents the file with its path }' is malformed. (...)");

因此,// I need something to represent the file with its path可以在不向我的班级添加字段_path的情况下轻松替换。像this.GetTheInConstructorArgumentedPath()这样的东西。

1 个答案:

答案 0 :(得分:1)

尝试将BaseStream转换为FileStream并从中获取名称(如果您认为它始终是您使用的文件流)。

(this.BaseStream as FileStream).Name