Exemple #1
0
        protected override string ToString(IList value, Type type, IConversionFactory factory)
        {
            Type valueType = value.GetType().GenericTypeArguments.FirstOrDefault();
            var  sb        = new StringBuilder();

            foreach (object entry in value)
            {
                sb.Append(factory.ToString(entry, valueType)).Append(" ");
            }

            return(sb.ToString().TrimEnd());
        }
Exemple #2
0
        public string Serialize(IPacket packet)
        {
            string header = packet.GetType().GetCustomAttribute <PacketHeaderAttribute>()?.Header;

            if (header == null)
            {
                _logger.Error($"Could not find header for {packet.GetType().FullName}");
                return(null);
            }

            string content = _conversionFactory.ToString(packet, packet.GetType());

            _logger.Debug($"Successfully serialized {packet.GetType().FullName}");
            return((header + " " + content).Trim());
        }
 protected override string ToString(short?value, Type type, IConversionFactory factory) => value == null ? "-1" : factory.ToString(value, typeof(short));
 protected override string ToString(Enum value, Type type, IConversionFactory factory) => factory.ToString(value, typeof(int));