Cascade
Loading...
Searching...
No Matches
Buzzware.Cascade.SuperModel Class Reference

A base class for Cascade models that handles property change notifications, property mutations, and proxy functionality. More...

Inheritance diagram for Buzzware.Cascade.SuperModel:
Buzzware.Cascade.Testing.Child Buzzware.Cascade.Testing.Child2 Buzzware.Cascade.Testing.ChildDetail Buzzware.Cascade.Testing.Parent Buzzware.Cascade.Testing.Parent2 Buzzware.Cascade.Testing.Thing Buzzware.Cascade.Testing.Toy

Public Member Functions

 SuperModel (SuperModel? proxyFor=null)
 Initializes a new instance of the SuperModel with an optional proxy model.
void __SetProxyFor (SuperModel? value, bool keepChanges, bool raiseIncoming)
 Sets a new proxy model and optionally retains changes or raises property change events.
IDictionary< string, object?> __GetChanges ()
 When acting as a proxy to another object, this method returns changes that have been made on this object vs the proxied object.
void __ApplyChanges (IDictionary< string, object?> changes)
 Applies a set of changes to the properties of the model.
void __ClearChanges ()
 Clears all changes made to the model, resetting the property state to the proxy model values.
void __mutateWith (Action< SuperModel > action)
 Executes an action that mutates the model, restoring the original mutation state afterwards.
void RaisePropertyChanged ([CallerMemberName] string propertyName=null)
 Raises a property changed notification for the specified property name.
SuperModel Clone (IDictionary< string, object?>? changes=null)
 Creates a shallow copy of the current SuperModel, optionally applying additional property changes.

Protected Member Functions

bool SetProperty< T > (ref T backingStore, T value, [CallerMemberName] string propertyName="", Action onChanged=null)
 Sets a property value and raises property change notifications if the value has changed.
GetProperty< T > (ref T backingStore, [CallerMemberName] string propertyName="", Action onChanged=null)
 Gets a property value, taking into account whether it's overridden by a proxy.
virtual void OnPropertyChanged (PropertyChangedEventArgs args)
 Raises the PropertyChanged event with the provided arguments.
void OnProxyForOnPropertyChanged (object sender, PropertyChangedEventArgs e)
 Handles property change events from the proxy model and re-raises them for this model.

Protected Attributes

SuperModel_proxyFor
readonly ConcurrentDictionary< string, bool > _propertySet = new ConcurrentDictionary<string, bool>()

Properties

bool __mutable [get, set]
 Gets or sets the mutable state of the model. When false, attempting to modify properties will throw a MutationAttemptException.
SuperModel__ProxyFor [get]
 The proxy model that this model is currently proxying for, if any.
bool __HasChanges [get]
 True if there are any uncommitted property changes in this model.

Events

PropertyChangedEventHandler? PropertyChanged

Detailed Description

A base class for Cascade models that handles property change notifications, property mutations, and proxy functionality.

Constructor & Destructor Documentation

◆ SuperModel()

Buzzware.Cascade.SuperModel.SuperModel ( SuperModel? proxyFor = null)
inline

Initializes a new instance of the SuperModel with an optional proxy model.

Parameters
proxyFor(optional) a SuperModel that this new instance will act as a proxy for.

Member Function Documentation

◆ __ApplyChanges()

void Buzzware.Cascade.SuperModel.__ApplyChanges ( IDictionary< string, object?> changes)
inline

Applies a set of changes to the properties of the model.

Parameters
changesA dictionary containing property names and the values to apply.

◆ __GetChanges()

IDictionary< string, object?> Buzzware.Cascade.SuperModel.__GetChanges ( )
inline

When acting as a proxy to another object, this method returns changes that have been made on this object vs the proxied object.

Returns
A dictionary of property names and their values.

◆ __mutateWith()

void Buzzware.Cascade.SuperModel.__mutateWith ( Action< SuperModel > action)
inline

Executes an action that mutates the model, restoring the original mutation state afterwards.

Parameters
actionThe action to perform which mutates the model.

◆ __SetProxyFor()

void Buzzware.Cascade.SuperModel.__SetProxyFor ( SuperModel? value,
bool keepChanges,
bool raiseIncoming )
inline

Sets a new proxy model and optionally retains changes or raises property change events.

Parameters
valueThe new proxy model to set.
keepChangesmaintain property changes while changing proxied instance
raiseIncomingraise PropertyChanged events for differing values in new proxy instance

◆ Clone()

SuperModel Buzzware.Cascade.SuperModel.Clone ( IDictionary< string, object?>? changes = null)
inline

Creates a shallow copy of the current SuperModel, optionally applying additional property changes.

Parameters
changesOptional dictionary of changes to apply to the cloned instance.
Returns
A new SuperModel instance that is a clone of the current instance with applied changes.

◆ GetProperty< T >()

T Buzzware.Cascade.SuperModel.GetProperty< T > ( ref T backingStore,
[CallerMemberName] string propertyName = "",
Action onChanged = null )
inlineprotected

Gets a property value, taking into account whether it's overridden by a proxy.

Template Parameters
TThe type of the property.
Parameters
backingStoreThe reference to the private backing field of the property.
propertyNameThe name of the property, automatically filled in by the compiler.
onChangedAn optional action to perform when the property value is accessed.
Returns
The current value of the property.

◆ OnPropertyChanged()

virtual void Buzzware.Cascade.SuperModel.OnPropertyChanged ( PropertyChangedEventArgs args)
inlineprotectedvirtual

Raises the PropertyChanged event with the provided arguments.

Parameters
argsThe property changed event arguments.

◆ OnProxyForOnPropertyChanged()

void Buzzware.Cascade.SuperModel.OnProxyForOnPropertyChanged ( object sender,
PropertyChangedEventArgs e )
inlineprotected

Handles property change events from the proxy model and re-raises them for this model.

Parameters
senderThe sender of the property changed event.
eThe property changed event arguments.

◆ RaisePropertyChanged()

void Buzzware.Cascade.SuperModel.RaisePropertyChanged ( [CallerMemberName] string propertyName = null)
inline

Raises a property changed notification for the specified property name.

Parameters
propertyNameThe name of the property.

◆ SetProperty< T >()

bool Buzzware.Cascade.SuperModel.SetProperty< T > ( ref T backingStore,
T value,
[CallerMemberName] string propertyName = "",
Action onChanged = null )
inlineprotected

Sets a property value and raises property change notifications if the value has changed.

Template Parameters
TThe type of the property.
Parameters
backingStoreThe reference to the private backing field of the property.
valueThe new value to set.
propertyNameThe name of the property, automatically filled in by the compiler.
onChangedAn optional action to perform when the property value changes.
Returns
True if the value has changed, otherwise false.
Exceptions
MutationAttemptExceptionThrown if a mutation is attempted when __mutable is false.

The documentation for this class was generated from the following file:
  • Buzzware.Cascade/SuperModel.cs