How to waste time
-
Considering this code snippet:
CSharpParser parser = new CSharpParser();
var compilationUnit = parser.Parse(File.OpenRead(path), path);using (stream = new MemoryStream())
{
var writer = new StreamWriter(stream);
var visitor = new CSharpOutputVisitor(writer, FormattingOptionsFactory.CreateMono());compilationUnit.AcceptVisitor(visitor);
stream.Position = 0;
var reader = new StreamReader(stream);
string s = reader.ReadToEnd();
}I spent about 4 hours of googling, debugging, etc. to figure out, why this code does not work, it was a mystery why "s" was always empty. I was convinced, this misbehavior was caused by (the really bad documented) NRefactory (v. 5)... But a simple writer.Flush() did the job... :mad: What a waste of time.
-
Considering this code snippet:
CSharpParser parser = new CSharpParser();
var compilationUnit = parser.Parse(File.OpenRead(path), path);using (stream = new MemoryStream())
{
var writer = new StreamWriter(stream);
var visitor = new CSharpOutputVisitor(writer, FormattingOptionsFactory.CreateMono());compilationUnit.AcceptVisitor(visitor);
stream.Position = 0;
var reader = new StreamReader(stream);
string s = reader.ReadToEnd();
}I spent about 4 hours of googling, debugging, etc. to figure out, why this code does not work, it was a mystery why "s" was always empty. I was convinced, this misbehavior was caused by (the really bad documented) NRefactory (v. 5)... But a simple writer.Flush() did the job... :mad: What a waste of time.
Nothing to say on the contents, but the subject should make into a book ;)
-
Considering this code snippet:
CSharpParser parser = new CSharpParser();
var compilationUnit = parser.Parse(File.OpenRead(path), path);using (stream = new MemoryStream())
{
var writer = new StreamWriter(stream);
var visitor = new CSharpOutputVisitor(writer, FormattingOptionsFactory.CreateMono());compilationUnit.AcceptVisitor(visitor);
stream.Position = 0;
var reader = new StreamReader(stream);
string s = reader.ReadToEnd();
}I spent about 4 hours of googling, debugging, etc. to figure out, why this code does not work, it was a mystery why "s" was always empty. I was convinced, this misbehavior was caused by (the really bad documented) NRefactory (v. 5)... But a simple writer.Flush() did the job... :mad: What a waste of time.
Henning Dieterichs wrote:
a simple writer.Flush()
That's bitten me a few times too.
-
Considering this code snippet:
CSharpParser parser = new CSharpParser();
var compilationUnit = parser.Parse(File.OpenRead(path), path);using (stream = new MemoryStream())
{
var writer = new StreamWriter(stream);
var visitor = new CSharpOutputVisitor(writer, FormattingOptionsFactory.CreateMono());compilationUnit.AcceptVisitor(visitor);
stream.Position = 0;
var reader = new StreamReader(stream);
string s = reader.ReadToEnd();
}I spent about 4 hours of googling, debugging, etc. to figure out, why this code does not work, it was a mystery why "s" was always empty. I was convinced, this misbehavior was caused by (the really bad documented) NRefactory (v. 5)... But a simple writer.Flush() did the job... :mad: What a waste of time.
How about using the good old
StringWriter
? No need to convert from text to bytes and back. -
How about using the good old
StringWriter
? No need to convert from text to bytes and back.Oh, I didn't know there is such a class ;) There's always something new to learn... So maybe it was actually not a full waste of time.
If you find spelling- or grammer-mistakes, please let me know, so that I can correct them (at least for me) - english is not my first language...
-
Henning Dieterichs wrote:
a simple writer.Flush()
That's bitten me a few times too.
PIEBALDconsult wrote:
Henning Dieterichs wrote:
a simple writer.Flush()
That's bitten me a few times too.
Same here. Intelisense needs updated to warn about asyncronicity.
Did you ever see history portrayed as an old man with a wise brow and pulseless heart, waging all things in the balance of reason? Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful? --Zachris Topelius Training a telescope on one’s own belly button will only reveal lint. You like that? You go right on staring at it. I prefer looking at galaxies. -- Sarah Hoyt
-
Considering this code snippet:
CSharpParser parser = new CSharpParser();
var compilationUnit = parser.Parse(File.OpenRead(path), path);using (stream = new MemoryStream())
{
var writer = new StreamWriter(stream);
var visitor = new CSharpOutputVisitor(writer, FormattingOptionsFactory.CreateMono());compilationUnit.AcceptVisitor(visitor);
stream.Position = 0;
var reader = new StreamReader(stream);
string s = reader.ReadToEnd();
}I spent about 4 hours of googling, debugging, etc. to figure out, why this code does not work, it was a mystery why "s" was always empty. I was convinced, this misbehavior was caused by (the really bad documented) NRefactory (v. 5)... But a simple writer.Flush() did the job... :mad: What a waste of time.
Or rather writer.AutoFlush = true would have done the trick too ;)
-
Or rather writer.AutoFlush = true would have done the trick too ;)
If you spotted that flushing (or the StreamWriter) is the problem, it does not matter whether you change to StringWriter, whether you call Flush() or set AutoFlush = true. But as long as you did not identify the StreamWriter as the problem, you are in the dark. So the gist of the story: Always call the whole code into question, but mostly the own...
If you find spelling- or grammer-mistakes, please let me know, so that I can correct them (at least for me) - english is not my first language...
-
If you spotted that flushing (or the StreamWriter) is the problem, it does not matter whether you change to StringWriter, whether you call Flush() or set AutoFlush = true. But as long as you did not identify the StreamWriter as the problem, you are in the dark. So the gist of the story: Always call the whole code into question, but mostly the own...
If you find spelling- or grammer-mistakes, please let me know, so that I can correct them (at least for me) - english is not my first language...
Yep true, i did not disagree with that. I was just mentioned an alternative of Flush() call :)