/// <summary>
        /// Not yet documented.
        /// </summary>
        public override void WritePrimitiveArray <T>(T[] array)
        {
            if (FormatterUtilities.IsPrimitiveArrayType(typeof(T)) == false)
            {
                throw new ArgumentException("Type " + typeof(T).Name + " is not a valid primitive array type.");
            }

            if (typeof(T) == typeof(byte))
            {
                string hex = ProperBitConverter.BytesToHexString((byte[])(object)array);

                this.Nodes.Add(new SerializationNode()
                {
                    Name  = string.Empty,
                    Entry = EntryType.PrimitiveArray,
                    Data  = hex
                });
            }
            else
            {
                this.Nodes.Add(new SerializationNode()
                {
                    Name  = string.Empty,
                    Entry = EntryType.PrimitiveArray,
                    Data  = array.LongLength.ToString(CultureInfo.InvariantCulture)
                });

                this.PushArray();

                Action <string, T> writer = (Action <string, T>) this.primitiveTypeWriters[typeof(T)];

                for (int i = 0; i < array.Length; i++)
                {
                    writer(string.Empty, array[i]);
                }

                this.EndArrayNode();
            }
        }
Пример #2
0
        public override string GetDataDump()
        {
            if (!this.Stream.CanRead)
            {
                return("Binary data stream for writing cannot be read; cannot dump data.");
            }

            if (!this.Stream.CanSeek)
            {
                return("Binary data stream cannot seek; cannot dump data.");
            }

            var oldPosition = this.Stream.Position;

            var bytes = new byte[oldPosition];

            this.Stream.Position = 0;
            this.Stream.Read(bytes, 0, (int)oldPosition);

            this.Stream.Position = oldPosition;

            return("Binary hex dump: " + ProperBitConverter.BytesToHexString(bytes));
        }