![]() |
Gondwana Game Engine Development (master) - 2.6.1
Gondwana is a cross-platform 2.5D game and rendering engine written in C#/.NET 8. It provides fine-grained control over rendering, timing, and scene composition, with built-in support for parallax, z-ordering, pixel overhang, collision detection, and particle effects. Gondwana targets desktop and web platforms using SkiaSharp for graphics and pluggable audio backends for desktop and browser targets.
|
A flexible, strongly-typed value container intended for runtime-attached metadata and ephemeral engine state. More...
Public Member Functions | |
| TypedValueBag () | |
| Initializes a new instance of the TypedValueBag class. | |
| TypedValueBag (TypedValueBag other) | |
| Initializes a new instance of the TypedValueBag class by performing a copy of another TypedValueBag. | |
| void | Set< T > (ValueKey< T > key, T value) |
| Stores a value in the bag under the specified key. | |
| bool | TryGet< T > (ValueKey< T > key, out T? value) |
| Attempts to retrieve a value from the bag using the specified key. | |
| T | Get< T > (ValueKey< T > key, T defaultValue=default!) |
| Retrieves a value from the bag using the specified key, or returns a default value if the key is not present. | |
| bool | Remove< T > (ValueKey< T > key) |
| Removes the value associated with the specified key from the bag. | |
| void | Clear () |
| Removes all values from the bag. | |
| void | MergeFrom (TypedValueBag? incoming, bool overwriteExisting=false) |
| Merges values from another TypedValueBag into this instance. | |
| bool | Contains (string keyName) |
| Determines whether the bag contains a value for the specified key name, regardless of type. | |
| bool | Contains< T > (ValueKey< T > key) |
| Determines whether the bag contains a value for the specified typed key. | |
| TypedValueBag | Clone () |
| Creates a copy of this TypedValueBag. | |
| Dictionary< string, object?> | ToDictionary () |
| Produces a shallow snapshot of the bag's current contents. | |
A flexible, strongly-typed value container intended for runtime-attached metadata and ephemeral engine state.
Values are stored internally as plain CLR objects keyed by string identifiers, but they are accessed externally through strongly-typed ValueKey<T> instances. This preserves compile-time safety for callers while avoiding any direct dependency on JSON serialization during ordinary runtime usage.
Unlike a JSON-token-based implementation, this class does not serialize or deserialize values on every set/get operation. It behaves as an in-memory typed bag first, with persistence concerns expected to be handled explicitly at the boundaries of the engine or application.
Values stored in a TypedValueBag are not preserved by JSON serialization. The bag is intended for runtime, transient, or otherwise non-persisted values, and engine-core properties that expose a TypedValueBag should typically be marked with JsonIgnoreAttribute. If an instance of this class is serialized directly, its contents are also intentionally ignored.
Cloning behavior is best-effort:
null, it remains null. This means immutable values behave exactly as expected, while mutable reference types can opt into stronger cloning semantics by implementing one of the supported clone contracts.
Definition at line 73 of file TypedValueBag.cs.
| Gondwana.TypedValueBag.TypedValueBag | ( | ) |
Initializes a new instance of the TypedValueBag class.
Definition at line 95 of file TypedValueBag.cs.
| Gondwana.TypedValueBag.TypedValueBag | ( | TypedValueBag | other | ) |
Initializes a new instance of the TypedValueBag class by performing a copy of another TypedValueBag.
Values are copied using the bag's internal clone strategy. Where possible, mutable values are cloned; where no supported clone mechanism exists, the original reference is reused.
| other | The source value bag to copy from. |
| ArgumentNullException | Thrown if other is null. |
This constructor is intended for scenarios such as runtime duplication, snapshot creation, undo/redo support, and general engine-state isolation. The exact depth of the copy depends on the clone capabilities of the stored values themselves.
Definition at line 118 of file TypedValueBag.cs.
| void Gondwana.TypedValueBag.Clear | ( | ) |
Removes all values from the bag.
Definition at line 271 of file TypedValueBag.cs.
| TypedValueBag Gondwana.TypedValueBag.Clone | ( | ) |
Creates a copy of this TypedValueBag.
The resulting bag is independent at the dictionary level. Individual stored values are duplicated according to the bag's clone strategy.
| bool Gondwana.TypedValueBag.Contains | ( | string | keyName | ) |
Determines whether the bag contains a value for the specified key name, regardless of type.
| keyName | The logical key name to test. |
true if the bag contains an entry with the specified key name; otherwise, false. | ArgumentException | Thrown if keyName is null, empty, or whitespace. |
Definition at line 319 of file TypedValueBag.cs.
| bool Gondwana.TypedValueBag.Contains< T > | ( | ValueKey< T > | key | ) |
Determines whether the bag contains a value for the specified typed key.
| T | The type associated with the key. |
| key | The strongly-typed key to test. |
true if the bag contains an entry with the specified key name; otherwise, false. | ArgumentException | Thrown if the key name is null, empty, or whitespace. |
Definition at line 340 of file TypedValueBag.cs.
| T Gondwana.TypedValueBag.Get< T > | ( | ValueKey< T > | key, |
| T | defaultValue = default! ) |
Retrieves a value from the bag using the specified key, or returns a default value if the key is not present.
| T | The expected type of the value. |
| key | The strongly-typed key identifying the value. |
| defaultValue | The value to return if the key is not found or the stored value is null. |
| ArgumentException | Thrown if the key name is null, empty, or whitespace. |
| InvalidCastException | Thrown if a value exists for the specified key but is not compatible with T . |
Definition at line 240 of file TypedValueBag.cs.
| void Gondwana.TypedValueBag.MergeFrom | ( | TypedValueBag? | incoming, |
| bool | overwriteExisting = false ) |
Merges values from another TypedValueBag into this instance.
| incoming | The source bag whose values will be copied into this bag. If null, the method performs no action. |
| overwriteExisting | If true, values in this bag will be replaced when the same key exists in incoming . If false, existing values are preserved and only missing keys are added. |
Values copied from incoming pass through the same clone strategy used by Clone(). This avoids unnecessary sharing where the stored types expose a supported clone mechanism.
Definition at line 293 of file TypedValueBag.cs.
| bool Gondwana.TypedValueBag.Remove< T > | ( | ValueKey< T > | key | ) |
Removes the value associated with the specified key from the bag.
| T | The type associated with the key. |
| key | The strongly-typed key identifying the value to remove. |
true if the value was found and removed; otherwise, false. | ArgumentException | Thrown if the key name is null, empty, or whitespace. |
Definition at line 262 of file TypedValueBag.cs.
| void Gondwana.TypedValueBag.Set< T > | ( | ValueKey< T > | key, |
| T | value ) |
Stores a value in the bag under the specified key.
If a value already exists for the given key, it is replaced.
| T | The type of value being stored. |
| key | The strongly-typed key identifying the value. |
| value | The value to store. A null value is stored explicitly. |
| ArgumentException | Thrown if the key name is null, empty, or whitespace. |
Definition at line 145 of file TypedValueBag.cs.
| Dictionary< string, object?> Gondwana.TypedValueBag.ToDictionary | ( | ) |
Produces a shallow snapshot of the bag's current contents.
This method is primarily intended for diagnostics, inspection, or external code that wants a plain dictionary view of the stored runtime values.
Definition at line 378 of file TypedValueBag.cs.
| bool Gondwana.TypedValueBag.TryGet< T > | ( | ValueKey< T > | key, |
| out T? | value ) |
Attempts to retrieve a value from the bag using the specified key.
| T | The expected type of the value. |
| key | The strongly-typed key identifying the value. |
| value | When this method returns true, contains the retrieved value. If the stored value is null, this output receives the default value of T . When the method returns false, this output also receives the default value of T . |
true if a value exists for the specified key; otherwise, false. | ArgumentException | Thrown if the key name is null, empty, or whitespace. |
| InvalidCastException | Thrown if a value exists for the specified key but is not compatible with T . |
This method distinguishes between three cases:
false. null: returns true, with value set to default. Definition at line 190 of file TypedValueBag.cs.