Class ModelViewSync<TModel, TView>
Keeps two collections of different types in sync based on mapping rules.
Namespace: NanoByte.Common.Dispatch
Assembly: NanoByte.Common.dll
Syntax
public sealed class ModelViewSync<TModel, TView> : Object where TModel : class, IChangeNotify<TModel> where TView : class
Type Parameters
Name | Description |
---|---|
TModel | The common base type of elements in the model. |
TView | The common base type of representations in the view. |
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.
Declaration
public ModelViewSync(MonitoredCollection<TModel> model, ICollection<TView> view)
Parameters
Type | Name | Description |
---|---|---|
MonitoredCollection<TModel> | model | The Model that can change on its own accord. |
ICollection<TView> | view | 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.
Declaration
public IEnumerable<TView> Representations { get; }
Property Value
Type | Description |
---|---|
IEnumerable<TView> |
Methods
Dispose()
Declaration
public void Dispose()
Initialize()
Must be called once, after all relevant mapping rules have been registered.
Declaration
public void Initialize()
Lookup(TView)
Looks up the Model element a View representation was created for.
Declaration
public TModel Lookup(TView representation)
Parameters
Type | Name | Description |
---|---|---|
TView | representation |
Returns
Type | Description |
---|---|
TModel |
Exceptions
Type | Condition |
---|---|
KeyNotFoundException | There is no match. |
Register<TSpecificModel, TSpecificView>(Func<TSpecificModel, TSpecificView>, Action<TSpecificModel, TSpecificView>)
Registers a mapping rule for a specific type of Model element.
Declaration
public void Register<TSpecificModel, TSpecificView>(Func<TSpecificModel, TSpecificView> create, Action<TSpecificModel, TSpecificView> update = null)
where TSpecificModel : class, TModel where TSpecificView : class, TView
Parameters
Type | Name | Description |
---|---|---|
Func<TSpecificModel, TSpecificView> | create | Callback that creates a View representation for a given Model element. |
System.Action<TSpecificModel, TSpecificView> | update | Callback that updates a View representation based on the state of a given Model element; can be |
Type Parameters
Name | Description |
---|---|
TSpecificModel | |
TSpecificView |
RegisterMultiple<TSpecificModel, TSpecificView>(Func<TSpecificModel, IEnumerable<TSpecificView>>, Action<TSpecificModel, TSpecificView>)
Registers a mapping rule for a specific type of Model element.
Declaration
public void RegisterMultiple<TSpecificModel, TSpecificView>(Func<TSpecificModel, IEnumerable<TSpecificView>> create, Action<TSpecificModel, TSpecificView> update = null)
where TSpecificModel : class, TModel where TSpecificView : class, TView
Parameters
Type | Name | Description |
---|---|---|
Func<TSpecificModel, IEnumerable<TSpecificView>> | create | Callback that creates a set of 0..n View representations for a given Model element. |
System.Action<TSpecificModel, TSpecificView> | update | Callback that updates a specific View representation based on the state of a given Model element; can be |
Type Parameters
Name | Description |
---|---|
TSpecificModel | |
TSpecificView |