public void Snapshot() { var population = new Default.DynamicPopulation( new DynamicMeta(new Pluralizer()), v => { v.AddUnit <Person, string>("FirstName"); v.AddUnit <Person, string>("LastName"); }); dynamic john = population.New <Person>(); dynamic jane = population.New <Person>(); john.FirstName = "John"; john.LastName = "Doe"; DynamicChangeSet snapshot1 = population.Snapshot(); jane.FirstName = "Jane"; jane.LastName = "Doe"; System.Collections.Generic.Dictionary <DynamicObject, object> changedFirstNames = snapshot1.ChangedRoles <Person>("FirstName"); System.Collections.Generic.Dictionary <DynamicObject, object> changedLastNames = snapshot1.ChangedRoles <Person>("LastName"); Assert.Single(changedFirstNames.Keys); Assert.Single(changedLastNames.Keys); Assert.Contains(john, changedFirstNames.Keys); Assert.Contains(john, changedLastNames.Keys); DynamicChangeSet snapshot2 = population.Snapshot(); changedFirstNames = snapshot2.ChangedRoles <Person>("FirstName"); changedLastNames = snapshot2.ChangedRoles <Person>("LastName"); Assert.Single(changedFirstNames.Keys); Assert.Single(changedLastNames.Keys); Assert.Contains(jane, changedFirstNames.Keys); Assert.Contains(jane, changedLastNames.Keys); }
public void Derive(DynamicChangeSet changeSet) { this.derivation.Derive(changeSet); System.Collections.Generic.Dictionary <DynamicObject, object> firstNames = changeSet.ChangedRoles <Person>("FirstName"); System.Collections.Generic.Dictionary <DynamicObject, object> lastNames = changeSet.ChangedRoles <Person>("LastName"); if (firstNames?.Any() == true || lastNames?.Any() == true) { System.Collections.Generic.IEnumerable <DynamicObject> people = firstNames.Union(lastNames).Select(v => v.Key).Distinct(); foreach (dynamic person in people) { person.FullName = $"{person.FullName} Chained"; } } }
public void Derive(DynamicChangeSet changeSet) { System.Collections.Generic.Dictionary <DynamicObject, object> firstNames = changeSet.ChangedRoles <Person>("FirstName"); System.Collections.Generic.Dictionary <DynamicObject, object> lastNames = changeSet.ChangedRoles <Person>("LastName"); if (firstNames?.Any() == true || lastNames?.Any() == true) { System.Collections.Generic.IEnumerable <DynamicObject> people = firstNames.Union(lastNames).Select(v => v.Key).Distinct(); foreach (dynamic person in people) { // Dummy updates ... person.FirstName = person.FirstName; person.LastName = person.LastName; person.DerivedAt = DateTime.Now; person.FullName = $"{person.FirstName} {person.LastName}"; } } }
public void Derive(DynamicChangeSet changeSet) { System.Collections.Generic.Dictionary <DynamicObject, object> fullNames = changeSet.ChangedRoles <Person>("FullName"); if (fullNames?.Any() == true) { System.Collections.Generic.IEnumerable <DynamicObject> people = fullNames.Select(v => v.Key).Distinct(); foreach (dynamic person in people) { person.Greeting = $"Hello {person.FullName}!"; } } }