/**
         * Clone the current record, via a call to serialise
         *  it, and another to Create a new record from the
         *  bytes.
         * May only be used for classes which don't have
         *  internal counts / ids in them. For those which
         *  do, a full record-aware serialise is needed, which
         *  allocates new ids / counts as needed.
         */
        public override Record CloneViaReserialise()
        {
            // Do it via a re-serialise
            // It's a cheat, but it works...
            byte[]            b    = this.Serialize();
            RecordInputStream rinp = new RecordInputStream(
                new System.IO.MemoryStream(b)
                );

            rinp.NextRecord();

            Record[] r = RecordFactory.CreateRecord(rinp);
            if (r.Length != 1)
            {
                throw new InvalidOperationException("Re-serialised a record to Clone it, but got " + r.Length + " records back!");
            }
            return(r[0]);
        }
Exemple #2
0
        public Record CloneViaReserialise()
        {
            // Do it via a re-serialization
            // It's a cheat, but it works...
            byte[] b = Serialize();
            using (MemoryStream ms = new MemoryStream(b))
            {
                RecordInputStream rinp = new RecordInputStream(ms);
                rinp.NextRecord();

                Record[] r = RecordFactory.CreateRecord(rinp);
                if (r.Length != 1)
                {
                    throw new InvalidOperationException("Re-serialised a record to clone it, but got " + r.Length + " records back!");
                }
                return(r[0]);
            }
        }