Ejemplo n.º 1
0
        /// <summary>
        /// Serializes <see cref="PivotDataState"/> into specified <see cref="Stream"/>.
        /// </summary>
        /// <param name="stream">The <see cref="Stream"/> used to write the data</param>
        /// <remarks>
        /// This method is not supported in .NET Standards (.NET Core) PivotData build (use Json.NET or protobuf-net instead).
        /// </remarks>
        public void Serialize(Stream stream)
        {
            using (var wr = new PivotDataStateBinaryWriter(stream)) {
                var t = typeof(PivotDataState);
                wr.Write(t.FullName);                  // type marker
                var ver = t.Assembly.GetName().Version;
                wr.Write(ver.Major);
                wr.Write(ver.Minor);

                wr.Write((ushort)4);                   // write number of serialized properties
                wr.Write("DimCount");
                wr.Write((uint)DimCount);
                wr.Write("KeyValues");
                WriteObject(wr, KeyValues);
                wr.Write("Values");
                WriteObject(wr, Values);
                wr.Write("ValueKeys");
                WriteValueKeys(wr, ValueKeys, DimCount);
            }
        }
Ejemplo n.º 2
0
        static void WriteObject(PivotDataStateBinaryWriter wr, object o)
        {
            var typeCode = o == null ? TypeCode.Empty : Type.GetTypeCode(o.GetType());

            if (typeCode != TypeCode.Object)
            {
                var typeCodeIdx = (byte)typeCode;
                wr.Write(typeCodeIdx);
                TypeCodeWriters[typeCodeIdx](wr, o);
            }
            else if (o is object[])
            {
                wr.Write((byte)ExtraTypeCode.ObjectArray);
                WriteObjectArray(wr, (object[])o);
            }
            else if (Key.IsEmpty(o))
            {
                wr.Write((byte)ExtraTypeCode.KeyEmpty);
            }
            else
            {
                throw new InvalidDataException("Unsupported object type: " + o.GetType().ToString());
            }
        }