Class ModelViewSync<TModel, TView>
Keeps two collections of different types in sync based on mapping rules.
[MustDisposeResource]
public sealed class ModelViewSync<TModel, TView> where TModel : class, IChangeNotify<TModel> where TView : class
Type Parameters
TModel
The common base type of elements in the model.
TView
The common base type of representations in the view.
- Inheritance
-
objectModelViewSync<TModel, TView>
- 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 System.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
model
MonitoredCollection<TModel>The Model that can change on its own accord.
view
ICollection<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 System.IDisposable.
Properties
Representations
All View representations created by the synchronizer.
public IEnumerable<TView> Representations { get; }
Property Value
- IEnumerable<TView>
Methods
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
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
representation
TView
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
create
Func<TSpecificModel, IEnumerable<TSpecificView>>Callback that creates a set of 0..n View representations for a given Model element.
update
Action<TSpecificModel, TSpecificView>Callback that updates a specific View representation based on the state of a given Model element; can be
null
.
Type Parameters
TSpecificModel
TSpecificView
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
create
Func<TSpecificModel, TSpecificView>Callback that creates a View representation for a given Model element.
update
Action<TSpecificModel, TSpecificView>Callback that updates a View representation based on the state of a given Model element; can be
null
.
Type Parameters
TSpecificModel
TSpecificView