GeneratePocoUpdateBson <TPoco, TTrackablePoco>(TrackablePocoMongoDbMapper <TPoco> mapper) where TPoco : ITrackablePoco <TPoco> where TTrackablePoco : ITrackable <TPoco> { return((update, trackablePoco, keyValues) => mapper.BuildUpdatesForSave(update, (TrackablePocoTracker <TPoco>)trackablePoco.Tracker, keyValues)); }
private static void BuildTrackablePocoProperty <TPoco>(PropertyItem item) where TPoco : ITrackablePoco <TPoco> { var mapper = new TrackablePocoMongoDbMapper <TPoco>(); item.Mapper = mapper; item.ExportToBson = (container, doc) => { var value = (TPoco)item.PropertyInfo.GetValue(container); if (value != null) { doc.Add(item.PropertyInfo.Name, mapper.ConvertToBsonDocument(value)); } }; item.ImportFromBson = (doc, container) => { var value = mapper.ConvertToTrackablePoco(doc, item.PropertyInfo.Name); item.PropertyInfo.SetValue(container, value); }; item.SaveChanges = (update, tracker, keyValues) => { var valueTracker = (TrackablePocoTracker <TPoco>)item.TrackerPropertyInfo.GetValue(tracker); if (valueTracker.HasChange == false) { return(null); } return(new List <UpdateDefinition <BsonDocument> > { mapper.BuildUpdatesForSave( update, valueTracker, keyValues.Concat(new object[] { item.PropertyInfo.Name }).ToArray()) }); }; }