Version 2.1.0.0

PropertyContextContainer class

Namespace: Sirenix.OdinInspector.Editor
Assembly: Sirenix.OdinInspector.Editor
public sealed class PropertyContextContainer

Contains a context for an InspectorProperty, which offers the ability to address persistent values by key across several editor GUI frames.

Use this in drawers to store contextual editor-only values such as the state of a foldout.

Inheritance
  • System.Object
  • PropertyContextContainer

Constructors

PropertyContextContainer(InspectorProperty)
Initializes a new instance of the PropertyContextContainer class.
public PropertyContextContainer(InspectorProperty property)
Parameters
InspectorProperty property

The property.

Exceptions
System.ArgumentNullException

property

Methods

Get<TValue>(OdinDrawer)
Gets a context value local to a drawer type for a given key, and creates a new instance of as a default value if the context doesn't already exist.
public PropertyContext<TValue> Get<TValue>(OdinDrawer drawerInstance)
    where TValue : new()
Parameters
OdinDrawer drawerInstance

An instance of the drawer type linked to the context value to get.

Returns
PropertyContext<TValue>

The found context.

Type Parameters
TValue

The type of the value.

Exceptions
System.ArgumentNullException

drawerInstance is null

Get<TValue>(OdinDrawer, TValue)
Gets a context value local to a drawer type for a given key, and creates a new instance of as a default value if the context doesn't already exist.
public PropertyContext<TValue> Get<TValue>(OdinDrawer drawerInstance, TValue defaultValue)
Parameters
OdinDrawer drawerInstance

An instance of the drawer type linked to the context value to get.

TValue defaultValue

The default value.

Returns
PropertyContext<TValue>

The found context.

Type Parameters
TValue

The type of the value.

Exceptions
System.ArgumentNullException

drawerInstance

System.ArgumentNullException

drawerInstance is null

Get<TValue>(OdinDrawer, String)
Gets a context value local to a drawer type for a given key, and creates a new instance of as a default value if the context doesn't already exist.
public PropertyContext<TValue> Get<TValue>(OdinDrawer drawerInstance, string key)
    where TValue : new()
Parameters
OdinDrawer drawerInstance

An instance of the drawer type linked to the context value to get.

System.String key

The key of the context value to get.

Returns
PropertyContext<TValue>

The found context.

Type Parameters
TValue

The type of the value.

Exceptions
System.ArgumentNullException

drawerInstance is null

Get<TValue>(OdinDrawer, String, TValue)

Gets a context value local to a drawer type for a given key, using a given default value if the context doesn't already exist.

public PropertyContext<TValue> Get<TValue>(OdinDrawer drawerInstance, string key, TValue defaultValue)
Parameters
OdinDrawer drawerInstance

An instance of the drawer type linked to the context value to get.

System.String key

The key of the context value to get.

TValue defaultValue

The default value to set if the context value doesn't exist yet.

Returns
PropertyContext<TValue>

The found context.

Type Parameters
TValue

The type of the value.

Exceptions
System.ArgumentNullException

drawerInstance is null

Get<TValue>(OdinDrawer, String, out TValue)
Gets a context value local to a drawer type for a given key, and creates a new instance of as a default value if the context doesn't already exist.
public bool Get<TValue>(OdinDrawer drawerInstance, string key, out TValue context)
    where TValue : class, new()
Parameters
OdinDrawer drawerInstance

System.String key

TValue context

Returns
System.Boolean

Returns true if a new context was created.

Type Parameters
TValue

Get<TValue>(OdinDrawer, String, out PropertyContext<TValue>)
Gets a context value local to a drawer type for a given key, and creates a new instance of as a default value if the context doesn't already exist.
public bool Get<TValue>(OdinDrawer drawerInstance, string key, out PropertyContext<TValue> context)
Parameters
OdinDrawer drawerInstance

System.String key

PropertyContext<TValue> context

Returns
System.Boolean

Returns true if a new context was created.

Type Parameters
TValue

Get<TValue>(OdinDrawer, String, Func<TValue>)

Gets a context value local to a drawer type for a given key, using a given delegate to generate a default value if the context doesn't already exist.

public PropertyContext<TValue> Get<TValue>(OdinDrawer drawerInstance, string key, Func<TValue> getDefaultValue)
Parameters
OdinDrawer drawerInstance

An instance of the drawer type linked to the context value to get.

System.String key

The key of the context value to get.

System.Func<TValue> getDefaultValue

A delegate for generating a default value.

Returns
PropertyContext<TValue>

The found context.

Type Parameters
TValue

The type of the value.

Exceptions
System.ArgumentNullException

drawerInstance is null

Get<TValue>(Type, String)
Gets a context value local to a drawer type for a given key, and creates a new instance of as a default value if the context doesn't already exist.
public PropertyContext<TValue> Get<TValue>(Type drawerType, string key)
    where TValue : new()
Parameters
System.Type drawerType

The type of the drawer.

System.String key

The key of the context value to get.

Returns
PropertyContext<TValue>

The found context.

Type Parameters
TValue

The type of the value.

Exceptions
System.ArgumentNullException

drawerInstance is null

Get<TValue>(Type, String, TValue)

Gets a context value local to a drawer type for a given key, using a given default value if the context doesn't already exist.

public PropertyContext<TValue> Get<TValue>(Type drawerType, string key, TValue defaultValue)
Parameters
System.Type drawerType

The type of the drawer.

System.String key

The key of the context value to get.

TValue defaultValue

The default value to set if the context value doesn't exist yet.

Returns
PropertyContext<TValue>

The found context.

Type Parameters
TValue

The type of the value.

Exceptions
System.ArgumentNullException

drawerInstance is null

Get<TValue>(Type, String, out PropertyContext<TValue>)
Gets a context value local to a drawer type for a given key, and creates a new instance of as a default value if the context doesn't already exist.
public bool Get<TValue>(Type drawerType, string key, out PropertyContext<TValue> context)
Parameters
System.Type drawerType

System.String key

PropertyContext<TValue> context

Returns
System.Boolean

Returns true if a new context was created.

Type Parameters
TValue

Get<TValue>(Type, String, Func<TValue>)

Gets a context value local to a drawer type for a given key, using a given delegate to generate a default value if the context doesn't already exist.

public PropertyContext<TValue> Get<TValue>(Type drawerType, string key, Func<TValue> getDefaultValue)
Parameters
System.Type drawerType

The type of the drawer.

System.String key

The key of the context value to get.

System.Func<TValue> getDefaultValue

A delegate for generating a default value.

Returns
PropertyContext<TValue>

The found context.

Type Parameters
TValue

The type of the value.

Exceptions
System.ArgumentNullException

drawerInstance is null

Get<TValue, TDrawer>(String)
Gets a context value local to a drawer type for a given key, and creates a new instance of as a default value if the context doesn't already exist.
public PropertyContext<TValue> Get<TValue, TDrawer>(string key)
    where TValue : new()
    where TDrawer : OdinDrawer
Parameters
System.String key

The key of the context value to get.

Returns
PropertyContext<TValue>

The found context.

Type Parameters
TValue

The type of the value.

TDrawer

The type of the drawer.

Exceptions
System.ArgumentNullException

drawerInstance is null

Get<TValue, TDrawer>(String, TValue)

Gets a context value local to a drawer type for a given key, using a given default value if the context doesn't already exist.

public PropertyContext<TValue> Get<TValue, TDrawer>(string key, TValue defaultValue)
    where TDrawer : OdinDrawer
Parameters
System.String key

The key of the context value to get.

TValue defaultValue

The default value to set if the context value doesn't exist yet.

Returns
PropertyContext<TValue>

The found context.

Type Parameters
TValue

The type of the value.

TDrawer

The type of the drawer.

Exceptions
System.ArgumentNullException

drawerInstance is null

Get<TValue, TDrawer>(String, out PropertyContext<TValue>)
Gets a context value local to a drawer type for a given key, and creates a new instance of as a default value if the context doesn't already exist.
public bool Get<TValue, TDrawer>(string key, out PropertyContext<TValue> context)
Parameters
System.String key

PropertyContext<TValue> context

Returns
System.Boolean

Returns true if a new context was created.

Type Parameters
TValue

TDrawer

Get<TValue, TDrawer>(String, Func<TValue>)

Gets a context value local to a drawer type for a given key, using a given delegate to generate a default value if the context doesn't already exist.

public PropertyContext<TValue> Get<TValue, TDrawer>(string key, Func<TValue> getDefaultValue)
    where TDrawer : OdinDrawer
Parameters
System.String key

The key of the context value to get.

System.Func<TValue> getDefaultValue

A delegate for generating a default value.

Returns
PropertyContext<TValue>

The found context.

Type Parameters
TValue

The type of the value.

TDrawer

The type of the drawer.

Exceptions
System.ArgumentNullException

drawerInstance is null

GetGlobal<T>(String)

Gets a global context value for a given key, and creates a new instance of as a default value if the context doesn't already exist.

Global contexts are not associated with any one specific drawer, and so are shared across all drawers for this property.

public PropertyContext<T> GetGlobal<T>(string key)
    where T : new()
Parameters
System.String key

The key of the context value to get.

Returns
PropertyContext<T>

The found context.

Type Parameters
T

The type of the context value to get.

GetGlobal<T>(String, T)

Gets a global context value for a given key, using a given default value if the context doesn't already exist.

Global contexts are not associated with any one specific drawer, and so are shared across all drawers for this property.

public PropertyContext<T> GetGlobal<T>(string key, T defaultValue)
Parameters
System.String key

The key of the context value to get.

T defaultValue

The default value to set if the context value doesn't exist yet.

Returns
PropertyContext<T>

The found context.

Type Parameters
T

The type of the context value to get.

GetGlobal<T>(String, Func<T>)

Gets a global context value for a given key, using a given delegate to generate a default value if the context doesn't already exist.

Global contexts are not associated with any one specific drawer, and so are shared across all drawers for this property.

public PropertyContext<T> GetGlobal<T>(string key, Func<T> getDefaultValue)
Parameters
System.String key

The key of the context value to get.

System.Func<T> getDefaultValue

A delegate for generating a default value.

Returns
PropertyContext<T>

The found context.

Type Parameters
T

The type of the context value to get.

GetPersistent<TValue>(OdinDrawer, String, TValue)
Gets a GlobalPersistentContext<T> object and creates a LocalPersistentContext<T> object for it.
public LocalPersistentContext<TValue> GetPersistent<TValue>(OdinDrawer drawer, string key, TValue defaultValue)
Parameters
OdinDrawer drawer

The instance of the drawer.

System.String key

The key for the context.

TValue defaultValue

The default value for the context.

Returns
LocalPersistentContext<TValue>

Type Parameters
TValue

The type of the value of the context.

GetPersistent<TValue>(OdinDrawer, String, out LocalPersistentContext<TValue>)
Gets a GlobalPersistentContext<T> object and creates a LocalPersistentContext<T> object for it. Returns true when the GlobalPersistentContext<T> is first created. Otherwise false.
public bool GetPersistent<TValue>(OdinDrawer drawer, string key, out LocalPersistentContext<TValue> context)
Parameters
OdinDrawer drawer

The instance of the drawer.

System.String key

The key for the context.

LocalPersistentContext<TValue> context

The LocalPersistentContext<T> object.

Returns
System.Boolean

Returns true when the GlobalPersistentContext<T> is first created. Otherwise false.

Type Parameters
TValue

The type of the value of the context.

SwapContext(PropertyContextContainer)
Swaps context values with a given PropertyContextContainer.
public void SwapContext(PropertyContextContainer otherContext)
Parameters
PropertyContextContainer otherContext

The context to swap with.