context: #region netDxf library licensed under the MIT License
  // 
  //                       netDxf library
  // Copyright (c) 2019-2021 Daniel Carvajal (haplokuon@gmail.com)
  // 
  // Permission is hereby granted, free of charge, to any person obtaining a copy
  // of this software and associated documentation files (the "Software"), to deal
  // in the Software without restriction, including without limitation the rights
  // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  // copies of the Software, and to permit persons to whom the Software is
  // furnished to do so, subject to the following conditions:
  // 
  // The above copyright notice and this permission notice shall be included in all
  // copies or substantial portions of the Software.
  // 
  // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  // SOFTWARE.
  // 
  #endregion
  
  using System;
  using System.Collections.Generic;
  using System.Diagnostics;
  using System.Globalization;
  using System.IO;
  
  namespace netDxf.IO
  {
      internal class TextCodeValueReader :
          ICodeValueReader
      {
          #region private fields
  
          private readonly TextReader reader;
          private short code;
          private object value;
          private long currentPosition;
  
          #endregion
  
          #region constructors
  
          public TextCodeValueReader(TextReader reader)
          {
              this.reader = reader;
              this.code = 0;
              this.value = null;
              this.currentPosition = 0;
          }
  
          #endregion
  
          #region public properties
  
          public short Code
          {
              get { return this.code; }
          }
  
          public object Value
          {
              get { return this.value; }
          }
  
          public long CurrentPosition
          {
              get { return this.currentPosition; }
          }
  
          #endregion
  
          #region public methods
  
          public void Next()
          {
              string readCode = this.reader.ReadLine();
              if (readCode == null)
              {
                  this.code = 0;
                  this.value = DxfObjectCode.EndOfFile;
              }
              else
              {
                  this.currentPosition += 1;
                  if (!short.TryParse(readCode, NumberStyles.Integer, CultureInfo.InvariantCulture, out this.code))
                  {
                      throw new Exception(string.Format("Code {0} not valid at line {1}", this.code, this.currentPosition));
                  }
                  this.value = this.ReadValue(this.reader.ReadLine());
                  this.currentPosition += 1;
              }
          }
  
          public byte ReadByte()
          {
              return (byte) this.value;
          }
  
          public byte[] ReadBytes()
          {
              return (byte[]) this.value;
          }
  
          public short ReadShort()
          {
              return (short) this.value;
          }
  
          public int ReadInt()
          {
              return (int) this.value;
          }
  
          public long ReadLong()
          {
              return (long) this.value;
          }
  
          public bool ReadBool()
          {
              return (bool) this.value;
          }
  
          public double ReadDouble()
          {
              return (double) this.value;
          }
  
          public string ReadString()
          {
              return (string) this.value;
          }
  
          public string ReadHex()
          {
              return (string) this.value;
          }
  
          public override string ToString()
          {
              return string.Format("{0}:{1}", this.code, this.value);
          }
  
          #endregion
  
          #region private methods
  
          private object ReadValue(string valueString)
          {
              if (this.code >= 0 && this.code <= 9) // string
              {
                  return this.ReadString(valueString);
              }
              if (this.code >= 10 && this.code <= 39) // double precision 3D point value
              {
                  return this.ReadDouble(valueString);
              }
              if (this.code >= 40 && this.code <= 59) // double precision floating point value
              {
                  return this.ReadDouble(valueString);
              }
              if (this.code >= 60 && this.code <= 79) // 16-bit integer value
              {
                  return this.ReadShort(valueString);
              }
              if (this.code >= 90 && this.code <= 99) // 32-bit integer value
              {
                  return this.ReadInt(valueString);
              }
              if (this.code == 100) // string (255-character maximum; less for Unicode strings)
              {
                  return this.ReadString(valueString);
              }
              if (this.code == 101) // string (255-character maximum; less for Unicode strings). This code is undocumented and seems to affect only the AcdsData in dxf version 2013
              {
                  return this.ReadString(valueString);
              }
              if (this.code == 102) // string (255-character maximum; less for Unicode strings)
              {
                  return this.ReadString(valueString);
              }
              if (this.code == 105) // string representing hexadecimal (hex) handle value
              {
                  return this.ReadHex(valueString);
              }
              if (this.code >= 110 && this.code <= 119) // double precision floating point value
              {
                  return this.ReadDouble(valueString);
              }
              if (this.code >= 120 && this.code <= 129) // double precision floating point value
              {
                  return this.ReadDouble(valueString);
              }
              if (this.code >= 130 && this.code <= 139) // double precision floating point value
              {
                  return this.ReadDouble(valueString);
              }
              if (this.code >= 140 && this.code <= 149) // double precision scalar floating-point value
              {
                  return this.ReadDouble(valueString);
              }
              if (this.code >= 160 && this.code <= 169) // 64-bit integer value
              {
                  return this.ReadLong(valueString);
              }
              if (this.code >= 170 && this.code <= 179) // 16-bit integer value
              {
                  return this.ReadShort(valueString);
              }
              if (this.code >= 210 && this.code <= 239) // double precision scalar floating-point value
              {
                  return this.ReadDouble(valueString);
              }
              if (this.code >= 270 && this.code <= 279) // 16-bit integer value
              {
                  return this.ReadShort(valueString);
              }
              if (this.code >= 280 && this.code <= 289) // 16-bit integer value
              {
                  return this.ReadShort(valueString);
              }
              if (this.code >= 290 && this.code <= 299) // byte (boolean flag value)
              {
                  return this.ReadBool(valueString);
              }
              if (this.code >= 300 && this.code <= 309) // arbitrary text string
              {
                  return this.ReadString(valueString);
              }
              if (this.code >= 310 && this.code <= 319) // string representing hex value of binary chunk
              {
                  return this.ReadBytes(valueString);
              }
              if (this.code >= 320 && this.code <= 329) // string representing hex handle value
              {
                  return this.ReadHex(valueString);
              }
              if (this.code >= 330 && this.code <= 369) // string representing hex object IDs
              {
                  return this.ReadHex(valueString);
              }
              if (this.code >= 370 && this.code <= 379) // 16-bit integer value
              {
                  return this.ReadShort(valueString);
              }
              if (this.code >= 380 && this.code <= 389) // 16-bit integer value
              {
                  return this.ReadShort(valueString);
              }
              if (this.code >= 390 && this.code <= 399) // string representing hex handle value
              {
                  return this.ReadHex(valueString);
              }
              if (this.code >= 400 && this.code <= 409) // 16-bit integer value
              {
                  return this.ReadShort(valueString);
              }
              if (this.code >= 410 && this.code <= 419) // string
              {
                  return this.ReadString(valueString);
              }
              if (this.code >= 420 && this.code <= 429) // 32-bit integer value
              {
                  return this.ReadInt(valueString);
              }
              if (this.code >= 430 && this.code <= 439) // string
              {
                  return this.ReadString(valueString);
              }
              if (this.code >= 440 && this.code <= 449) // 32-bit integer value
              {
                  return this.ReadInt(valueString);
              }
              if (this.code >= 450 && this.code <= 459) // 32-bit integer value
              {
                  return this.ReadInt(valueString);
              }
              if (this.code >= 460 && this.code <= 469) // double-precision floating-point value
              {
                  return this.ReadDouble(valueString);
              }
  
gt:             if (this.code >= 470 && this.code <= 479) // string