示例#1
0
        public override string ToString()
        {
            ACommand.Sendable sendable = this as ACommand.Sendable;
            if (sendable != null)
            {
                return(sendable.Serialize());
            }
            else
            {
                StringBuilder sb = new StringBuilder();
                sb.Append(base.ToString());
                sb.Append("[");
                foreach (var propertyInfo in this.GetType().GetProperties())
                {
                    sb.Append(propertyInfo.Name);
                    sb.Append(":");
                    sb.Append(propertyInfo.GetValue(this, null));
                    sb.Append(";");
                }

                foreach (var fieldInfo in this.GetType().GetFields())
                {
                    sb.Append(fieldInfo.Name);
                    sb.Append(":");
                    sb.Append(fieldInfo.GetValue(this));
                    sb.Append(";");
                }
                sb.Append("]");

                return(sb.ToString());
            }
        }
示例#2
0
 public static async Task SendAsync(this ACommand.Sendable instance, NetworkStream s)
 {
     if (instance == null)
     {
         throw new ArgumentNullException("Instance can not be null.");
     }
     await s.WriteLineAsync(instance.Serialize());
 }
示例#3
0
 public static string ToString(this ACommand.Sendable instance)
 {
     if (instance == null)
     {
         throw new ArgumentNullException("Instance can not be null.");
     }
     return(instance.Serialize());
 }
示例#4
0
 public virtual string GetSendableCommand(ACommand s)
 {
     ACommand.Sendable commandSendable = commandsFactory.Transfer(s);
     if (commandSendable == null)
     {
         throw new ArgumentException("Protocol (" + this.GetType().Name + ") do not know command type: " + s.GetType().Name);
     }
     return(commandSendable.Serialize());
 }