DataBagclass

A lightweight, lazily-allocated key/value store for stashing arbitrary typed data on an object. The backing dictionary isn't created until you store something, so empty bags are essentially free. Not thread-safe - use it from a single thread (usually the main thread).

objectDataBag
Namespace
Sandbox
Assembly
Sandbox.System
Declaration
public sealed class Sandbox.DataBag

Constructors1

Showing 1 constructors

Methods5

Showing 5 methods

public void Clear()PUBLIC

Remove everything from the bag.

Returns:void

public T Get(string key, T fallback = null)PUBLIC

Get the value stored under `key`, or `fallback` if there's nothing there or it's a different type.

ParameterTypeDescription
keystring
fallback = nullT
Returns:T

public bool Has(string key)PUBLIC

Whether anything is stored under `key`.

ParameterTypeDescription
keystring
Returns:bool

public bool Remove(string key)PUBLIC

Remove the value stored under `key`. Returns true if something was removed.

ParameterTypeDescription
keystring
Returns:bool

public void Set(string key, T value)PUBLIC

Store a value under `key`, replacing anything already there.

ParameterTypeDescription
keystring
valueT
Returns:void

On this page