/// <summary>
        /// reply WILL to this received statement.
        /// </summary>
        /// <param name="NetStream"></param>
        public virtual TelnetCommand BuildWillReply( )
        {
            var replyStmt =
                new TelnetCommand(CommandCode.WILL, this.Subject.Value);

            return(replyStmt);
        }
        public static TelnetCommand Factory(InputByteArray InputArray, CommandCode CmdCode)
        {
            TelnetCommand telnetCmd = null;

            TelnetSubject?subject = null;

            if (InputArray.RemainingLength > 2)
            {
                subject = InputArray.PeekTelnetSubject(2);
            }

            if (CmdCode == CommandCode.SE)
            {
                telnetCmd = new EndSubNegCommand(InputArray);
            }
            else if (CmdCode == CommandCode.EOR)
            {
                telnetCmd = new EOR_Command(InputArray);
            }

            else if (subject == null)
            {
                telnetCmd = new TelnetCommand(InputArray, CmdCode);
            }

            else if (subject.Value == TelnetSubject.NewEnviron)
            {
                telnetCmd = new NewEnvironCommand(InputArray, CmdCode);
            }

            else if (subject.Value == TelnetSubject.TerminalType)
            {
                telnetCmd = new TerminalTypeCommand(InputArray, CmdCode);
            }

            else if (subject.Value == TelnetSubject.END_OF_RECORD)
            {
                telnetCmd = new EndOfRecordStatement(InputArray, CmdCode);
            }

            else if (subject.Value == TelnetSubject.TRANSMIT_BINARY)
            {
                telnetCmd = new TransmitBinaryCommand(InputArray, CmdCode);
            }
            else if (subject.Value == TelnetSubject.NAWS)
            {
                telnetCmd = new NawsStatement(InputArray, CmdCode);
            }
            else if (subject.Value == TelnetSubject.ECHO)
            {
                throw new Exception("echo subject of " + CmdCode.ToString() + " command.");
            }
            else
            {
                throw new Exception("Unexpect telnet command");
            }

            return(telnetCmd);
        }
        /// <summary>
        /// read next Telnet command byte sequence from the input byte array.
        /// </summary>
        /// <param name="InputArray"></param>
        /// <returns></returns>
        public static TelnetCommand NextTelnetCommand(
            this InputByteArray InputArray)
        {
            TelnetCommand cmd  = null;
            var           code = InputArray.PeekTelnetCommandCode( );

            if (code != null)
            {
                cmd = TelnetCommand.Factory(InputArray, code.Value);
            }
            return(cmd);
        }
        /// <summary>
        /// reply to the DO command with a WILL or WONT command as per NegotiateSettings.
        /// </summary>
        /// <param name="Settings"></param>
        /// <returns></returns>
        public TelnetCommand BuildReply(NegotiateSettings Settings)
        {
            TelnetCommand reply  = null;
            var           option = this.Subject.Value;

            if (Settings.OptionDict.ContainsKey(option) == true)
            {
                var cmdCode = Settings.OptionDict[option];
                reply = new TelnetCommand(cmdCode, this.Subject.Value);
            }
            else
            {
                reply = new TelnetCommand(CommandCode.WONT, this.Subject.Value);
            }
            return(reply);
        }