Sunday, 15 June 2014

c# - Is there a way to check if a TextWriter is closed? -


I am writing a class that exports data to a CSV file, and its constructor to the text worker is. The reason I am using a TextWriter instead of a StreamWriter, so that it can make the test easier: I write to a single creator a StreamWriter (which writes files, desired usage-case) and to write a stringword (Which is useful for testing).

In my constructor I want to do some assumptions on passing in TextWriter. The problem is that I can not know how the text worker is open or closed. If StreamStatus property is zero then it is possible for StreamWriter that TextWriter does not have this property but is there any other way, if a text worker is open or not?

You can try this way:

  if ( Author.beststream! = Null) {author. Virline ("the author is open"); } Other {message box. Show ("the author is closed"); }  

That is, if is the basestream faucet , then the author has already been dealt with.

It is also recommended to use the block for this to be used because it takes care of it.


No comments:

Post a Comment