Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. How to waste time

How to waste time

Scheduled Pinned Locked Moved The Lounge
tutorialcareer
9 Posts 6 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    Henning Dieterichs
    wrote on last edited by
    #1

    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.

    V P D Z 4 Replies Last reply
    0
    • H Henning Dieterichs

      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.

      V Offline
      V Offline
      Vitaly Tomilov
      wrote on last edited by
      #2

      Nothing to say on the contents, but the subject should make into a book ;)

      1 Reply Last reply
      0
      • H Henning Dieterichs

        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.

        P Offline
        P Offline
        PIEBALDconsult
        wrote on last edited by
        #3

        Henning Dieterichs wrote:

        a simple writer.Flush()

        That's bitten me a few times too.

        D 1 Reply Last reply
        0
        • H Henning Dieterichs

          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.

          D Offline
          D Offline
          Daniel Grunwald
          wrote on last edited by
          #4

          How about using the good old StringWriter? No need to convert from text to bytes and back.

          H 1 Reply Last reply
          0
          • D Daniel Grunwald

            How about using the good old StringWriter? No need to convert from text to bytes and back.

            H Offline
            H Offline
            Henning Dieterichs
            wrote on last edited by
            #5

            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...

            1 Reply Last reply
            0
            • P PIEBALDconsult

              Henning Dieterichs wrote:

              a simple writer.Flush()

              That's bitten me a few times too.

              D Offline
              D Offline
              Dan Neely
              wrote on last edited by
              #6

              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

              1 Reply Last reply
              0
              • H Henning Dieterichs

                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.

                Z Offline
                Z Offline
                zenwalker1985
                wrote on last edited by
                #7

                Or rather writer.AutoFlush = true would have done the trick too ;)

                My cUr10U5 w0rlD

                H 1 Reply Last reply
                0
                • Z zenwalker1985

                  Or rather writer.AutoFlush = true would have done the trick too ;)

                  My cUr10U5 w0rlD

                  H Offline
                  H Offline
                  Henning Dieterichs
                  wrote on last edited by
                  #8

                  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...

                  Z 1 Reply Last reply
                  0
                  • H Henning Dieterichs

                    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...

                    Z Offline
                    Z Offline
                    zenwalker1985
                    wrote on last edited by
                    #9

                    Yep true, i did not disagree with that. I was just mentioned an alternative of Flush() call :)

                    My cUr10U5 w0rlD

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups