// /** // * File: ODB.cs // * Author: haraldwolff // * // * This file and it's content is copyrighted by the Author and / or copyright holder. // * Any use wihtout proper permission is illegal and may lead to legal actions. // * // * // **/ using System; using System.IO; using System.Collections.Generic; using ln.types.serialize; using System.Linq; namespace ln.types.odb { class ODBObjectWriter : ObjectWriter { public IPersistent[] ReferencedPersistents => referencedPersistents.Values.ToArray(); public Guid[] ReferencedPersistentIDs => referencedPersistents.Keys.ToArray(); private Dictionary referencedPersistents = new Dictionary(); public ODBObjectWriter(Stream stream) : base(stream) {} public override object QueryReference(object o) { if (o is IPersistent) { IPersistent persistent = o as IPersistent; Guid persistenceID = persistent.GetPersistenceID(); if (!referencedPersistents.ContainsKey(persistenceID)) referencedPersistents.Add(persistenceID, persistent); return persistenceID; } return base.QueryReference(o); } } }