NanoByte.Common  2.9.0
NanoByte.Common.Dispatch.ModelViewSync< TModel, TView > Class Template Reference

Keeps two collections of different types in sync based on mapping rules. More...

Inheritance diagram for NanoByte.Common.Dispatch.ModelViewSync< TModel, TView >:

Public Member Functions

 ModelViewSync (MonitoredCollection< TModel > model, ICollection< TView > view)
 Creates a new Model-View synchronizer. More...
 
void Initialize ()
 Must be called once, after all relevant mapping rules have been registered. More...
 
void Dispose ()
 
TModel Lookup (TView representation)
 Looks up the Model element a View representation was created for. More...
 
void RegisterMultiple< TSpecificModel, TSpecificView > (Func< TSpecificModel, IEnumerable< TSpecificView >> create, Action< TSpecificModel, TSpecificView >? update=null)
 Registers a mapping rule for a specific type of Model element. More...
 
void Register< TSpecificModel, TSpecificView > (Func< TSpecificModel, TSpecificView > create, Action< TSpecificModel, TSpecificView >? update=null)
 Registers a mapping rule for a specific type of Model element. More...
 

Properties

IEnumerable< TView > Representations [get]
 All View representations created by the synchronizer. More...
 

Detailed Description

Keeps two collections of different types in sync based on mapping rules.

Template Parameters
TModelThe common base type of elements in the model.
TViewThe common base type of representations in the view.

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.

Type Constraints
TModel :class 
TModel :IChangeNotify<TModel> 
TView :class 

Constructor & Destructor Documentation

◆ ModelViewSync()

NanoByte.Common.Dispatch.ModelViewSync< TModel, TView >.ModelViewSync ( MonitoredCollection< TModel >  model,
ICollection< TView >  view 
)
inline

Creates a new Model-View synchronizer.

Parameters
modelThe Model that can change on its own accord.
viewThe View that is to be automatically updated to reflect changes in the Model.

Member Function Documentation

◆ Initialize()

void NanoByte.Common.Dispatch.ModelViewSync< TModel, TView >.Initialize ( )
inline

Must be called once, after all relevant mapping rules have been registered.

◆ Lookup()

TModel NanoByte.Common.Dispatch.ModelViewSync< TModel, TView >.Lookup ( TView  representation)

Looks up the Model element a View representation was created for.

Exceptions
KeyNotFoundExceptionThere is no match.

◆ Register< TSpecificModel, TSpecificView >()

void NanoByte.Common.Dispatch.ModelViewSync< TModel, TView >.Register< TSpecificModel, TSpecificView > ( Func< TSpecificModel, TSpecificView >  create,
Action< TSpecificModel, TSpecificView >?  update = null 
)
inline

Registers a mapping rule for a specific type of Model element.

Parameters
createCallback that creates a View representation for a given Model element.
updateCallback that updates a View representation based on the state of a given Model element; can be null.
Type Constraints
TSpecificModel :class 
TSpecificModel :TModel 
TSpecificView :class 
TSpecificView :TView 

◆ RegisterMultiple< TSpecificModel, TSpecificView >()

void NanoByte.Common.Dispatch.ModelViewSync< TModel, TView >.RegisterMultiple< TSpecificModel, TSpecificView > ( Func< TSpecificModel, IEnumerable< TSpecificView >>  create,
Action< TSpecificModel, TSpecificView >?  update = null 
)
inline

Registers a mapping rule for a specific type of Model element.

Parameters
createCallback that creates a set of 0..n View representations for a given Model element.
updateCallback that updates a specific View representation based on the state of a given Model element; can be null.
Type Constraints
TSpecificModel :class 
TSpecificModel :TModel 
TSpecificView :class 
TSpecificView :TView 

Property Documentation

◆ Representations

IEnumerable<TView> NanoByte.Common.Dispatch.ModelViewSync< TModel, TView >.Representations
get

All View representations created by the synchronizer.


The documentation for this class was generated from the following file: