Get a TextReader from a Stream?

后端 未结 4 1581
北恋
北恋 2021-02-04 23:21

I\'m trying to read an embedded text file with System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(resource); but it gives me a Stream

4条回答
  •  温柔的废话
    2021-02-04 23:44

    You need to get a StreamReader from it (TextReader is an abstract base class of StreamReader and StringReader). Something like:

    var stream = System.Reflection.Assembly.GetExecutingAssembly().
        GetManifestResourceStream(resource);
    var reader = new StreamReader(stream);
    var text = reader.ReadToEnd();
    

提交回复
热议问题