Sage Modeling and Simulation Library

SmartPropertyBag Class

NOTE: This is an older class whose utility may have been subsumed into other, newer .NET classes such as tuples and the mechanisms for lambda expressions. However, it is used in various places in the library, so it is retained.

A SmartPropertyBag (SPB) is at its basic level, a collection of name/value pairs. The power of a smart property bag lies in the fact that entries in the bag can be any of a number of specialized types -

Simple data (Value) : Any primitive that is convertible to a double, string or boolean.

Expression : An expression is a string such as "X + Y" that, when queried (assuming that X and Y are entries in the bag) is evaluated and returns the result of the evaluation.

Alias : A name value pair that points to an entry in another SPB.

Delegate : A delegate to a method that returns a double. When this entry is requested, the delegate is called and the resulting value is returned.

SPB : An entry in a SPB may be another SPB, which effectively becomes a child of this SPB. Thus, a SPB representing a truck may contain several other SPBs representing each load placed on that truck, and thereafter, the key "TruckA.LoadB.Customer" will retrieve, for example, a string containing the name or ID of the customer for whom load B is destined.

ISnapShottable : Any arbitrary object can be stored in a SPB if it implements the ISnapshottable interface. The SPB enables storage of booleans, doubles, and strings through the use of internal classes SPBBooleanWrapper, SPBDoubleValueWrapper, and SPBStringWrapper, respectively - each of which implements ISnapshottable.


A SmartPropertyBag can also be write-locked, allowing it temporarily or permanently to be read but not written.

A SmartPropertyBag also maintains a memento, an object that records the SPB's internal state and can restore that state at any time. This is useful for a model element that may need to be "rolled back" to a prior state. This memento is only recalculated when it is requested, and only the portions that have changed are re-recorded into the memento.

A SmartPropertyBag is useful when an application is required to support significant configurability at run time. An example might be a modeling tool that incorporates the concept of a vessel for chemical manufacturing, but does not know at the time of app design, all of the characteristics that will be of interest in that vessel, and all of the attachments that will be made available on that vessel at a later time or by the designer using the application.

Namespace:  Highpoint.Sage.SimCore
Assembly:  Sage4 (in Sage4.dll)

Syntax


Inheritance Hierarchy


Object
  Highpoint.Sage.SimCore..::..SmartPropertyBag