/// <summary> /// Update or fill the collection using the mapping entry /// </summary> private static void UpdateCollection(object currentValue, Type memberType, ICustomAttributeProvider attributeProvider, Entry rootEntry, ICollectionStrategy strategy, ICustomSerialization customSerialization) { var currentCollection = currentValue as ICollection; // Loop over the collection and update the entries that are still present if (currentCollection != null) { foreach (var key in strategy.Keys()) { var item = strategy.ElementAt(key); var match = rootEntry.SubEntries.Find(se => se.Identifier == key); if (match == null) { strategy.Removed(key); continue; } if (match.Value.Type < EntryValueType.Class) { item = CreatePrimitiveOrEnum(memberType, match.Value, customSerialization.FormatProvider); } else { UpdateInstance(item, match, customSerialization); } strategy.Updated(match, item); } } // Add new entries to the collection foreach (var subEntry in rootEntry.SubEntries.Where(se => se.Identifier == Entry.CreatedIdentifier)) { object item; // All value types if (subEntry.Value.Type < EntryValueType.Class) { // Create value type item = CreatePrimitiveOrEnum(memberType, subEntry.Value, customSerialization.FormatProvider); } else { // Create and update reference types item = customSerialization.CreateInstance(memberType, attributeProvider, subEntry); item = UpdateInstance(item, subEntry, customSerialization); } strategy.Added(subEntry, item); } // Finalize all operations strategy.Flush(); }
private ICollectionStrategy <TModel> BuildStrategy(Type modelType) { var dataAttr = modelType.GetCustomAttribute <DataProviderAttribute>(); if (dataAttr != null) { strategy = dataAttr.DataProvider.InstantiateAs <ICollectionStrategy <TModel> >(); } else { strategy = new UnityEditorModelCollection <TModel>(); } return(strategy); }
/// <summary> /// Initializes a new instance of <see cref="EntityContextConnection"/> /// </summary> /// <param name="configuration"><see cref="EntityContextConfiguration">Configuration</see> to use</param> /// <param name="collectionStrategy"><see cref="ICollectionStrategy"/> to use for types</param> public EntityContextConnection(EntityContextConfiguration configuration, ICollectionStrategy collectionStrategy) { _configuration = configuration; CollectionStrategy = collectionStrategy; }
public void ChangeDataStrategy(ICollectionStrategy <TModel> newStrategy) { strategy = newStrategy; }