Class ModelViewSync<TModel, TView>
Keeps two collections of different types in sync based on mapping rules.
public sealed class ModelViewSync<TModel, TView> : IDisposable where TModel : class, IChangeNotify<TModel> where TView : class
Type Parameters
TModelThe common base type of elements in the model.
TViewThe common base type of representations in the view.
- Inheritance
-
objectModelViewSync<TModel, TView>
- Implements
- Extension Methods
Remarks
Useful for maintaining View representations for a set of mutable Model elements in a Model-View-Controller/Presenter design. Generated View representations will automatically be disposed on removal, if they implement IDisposable.
Constructors
ModelViewSync(MonitoredCollection<TModel>, ICollection<TView>)
Keeps two collections of different types in sync based on mapping rules.
public ModelViewSync(MonitoredCollection<TModel> model, ICollection<TView> view)
Parameters
modelMonitoredCollection<TModel>The Model that can change on its own accord.
viewICollection<TView>The View that is to be automatically updated to reflect changes in the Model.
Remarks
Useful for maintaining View representations for a set of mutable Model elements in a Model-View-Controller/Presenter design. Generated View representations will automatically be disposed on removal, if they implement IDisposable.
Properties
Representations
All View representations created by the synchronizer.
public IEnumerable<TView> Representations { get; }
Property Value
- IEnumerable<TView>
Methods
Dispose()
public void Dispose()
Initialize()
Must be called once, after all relevant mapping rules have been registered.
public void Initialize()
Lookup(TView)
Looks up the Model element a View representation was created for.
public TModel Lookup(TView representation)
Parameters
representationTView
Returns
- TModel
Exceptions
- KeyNotFoundException
There is no match.
RegisterMultiple<TSpecificModel, TSpecificView>(Func<TSpecificModel, IEnumerable<TSpecificView>>, Action<TSpecificModel, TSpecificView>?)
Registers a mapping rule for a specific type of Model element.
public void RegisterMultiple<TSpecificModel, TSpecificView>(Func<TSpecificModel, IEnumerable<TSpecificView>> create, Action<TSpecificModel, TSpecificView>? update = null) where TSpecificModel : class, TModel where TSpecificView : class, TView
Parameters
createFunc<TSpecificModel, IEnumerable<TSpecificView>>Callback that creates a set of 0..n View representations for a given Model element.
updateAction<TSpecificModel, TSpecificView>Callback that updates a specific View representation based on the state of a given Model element; can be
null.
Type Parameters
TSpecificModelTSpecificView
Register<TSpecificModel, TSpecificView>(Func<TSpecificModel, TSpecificView?>, Action<TSpecificModel, TSpecificView>?)
Registers a mapping rule for a specific type of Model element.
public void Register<TSpecificModel, TSpecificView>(Func<TSpecificModel, TSpecificView?> create, Action<TSpecificModel, TSpecificView>? update = null) where TSpecificModel : class, TModel where TSpecificView : class, TView
Parameters
createFunc<TSpecificModel, TSpecificView>Callback that creates a View representation for a given Model element.
updateAction<TSpecificModel, TSpecificView>Callback that updates a View representation based on the state of a given Model element; can be
null.
Type Parameters
TSpecificModelTSpecificView