private IEnumerable <Datom> SerializeRecurse <T>(T @object, SerializationSettings settings, HashSet <Reference> visited) { var typeHandler = MessageTypeHandlers <T> .Value; var typeId = typeHandler.TypeRegistration.TypeId; var identity = typeHandler.KeyGetter(@object); var reference = new Reference() { Type = typeId, Identity = identity }; if (!visited.Contains(reference)) { visited.Add(reference); var prototype = new Datom ( settings.AggregateType, settings.AggregateId, typeId, identity, 0, 0, new byte[0], settings.TransactionId, settings.Action ); var simpleFieldsDatoms = typeHandler.FieldsByParameterNumber .Where(x => x.Value.FieldClass == FieldClass.Simple) .SelectMany(x => ((SimpleField <T>)x.Value).Serialize(@object, prototype)); var referenceFieldsDatoms = typeHandler.FieldsByParameterNumber .Where(x => x.Value.FieldClass == FieldClass.Reference) .SelectMany(x => { var referenceField = ((ReferenceField <T>)x.Value); var recurse = _serializeRecurseForTypeByTypeId[referenceField.ReferencedTypeId]; return(referenceField.Serialize(@object, prototype) .Concat( referenceField.Follow(@object) .SelectMany(referenced => recurse(referenced, settings, visited)) )); }); return(simpleFieldsDatoms.Concat(referenceFieldsDatoms)); } else { return(Enumerable.Empty <Datom>()); } }
public string DebugFormatDatom(Datom datom) { return(_debugFormatters[new Tuple <ushort, ushort>(datom.Type, datom.Parameter)](datom)); }