API reference
API reference
Select your platform
No SDKs available
No versions available

ValueToClassDecorator Class

Base class for Context-based decoration, specifically where the instance being decorated (InstanceT ) is not a class type, but the data being used as a decoration (DecorationT ) is.
Automatically removes decoration relationships when the decoration is cleaned up.
As with ClassToClassDecorator<InstanceT, DecorationT> and other descendants of DecoratorBase<InstanceT, DecorationT>, a goal of ValueToClassDecorator is to be non-invasive and avoid altering behavior based on decoration. However, because InstanceT is not a class type, its lifecycle cannot be used to determine when to automatically remove its entry in the decorator; thus, even if the value decorated is no longer in use, decoration based on the instance lifecycle would continue to "pin the decoration into existence" indefinitely. To avoid this, ValueToClassDecorator automatically cleans up its decoration relationships based on the lifecycle of the decoration, meaning once no references to the decoration remain outside the decorator, the relationship will be cleaned up to avoid leaks.
There are scenarios where this behavior is undesirable where it is better for the decorator to own a reference to the decoration such that it can "pin it into existence" despite the fact that InstanceT has no lifecycle. In such scenarios, a simple dictionary singleton on the Context is a better choice than any descendent of DecoratorBase<InstanceT, DecorationT> as only manual lifecycle management is appropriate.

Constructors

ValueToClassDecorator ()
Signature
Oculus.Interaction.ValueToClassDecorator< InstanceT, DecorationT >.ValueToClassDecorator()

Methods

AddDecoration ( instance , decoration )
Associates an instance with a decoration.
If this instance was already decorated, the old decoration is removed. If there were any outstanding asynchronous requests for the decoration of this instance (from prior calls to GetDecorationAsync(InstanceT), those requests will be fulfilled as part of this operation.
Signature
void Oculus.Interaction.ValueToClassDecorator< InstanceT, DecorationT >.AddDecoration(InstanceT instance, DecorationT decoration)
Parameters
instance: InstanceT  The instance to be decorated
decoration: DecorationT  The decoration to be added to this instance
Returns
void
GetDecorationAsync ( instance )
Asynchronously retrieves the decoration associated with an instance.
If the instance already has a decoration, the returned task is immediately completed with the currently-available decoration. If no decoration is yet available for this instance, the returned task will only be completed during the call to AddDecoration(InstanceT, DecorationT) for the instance in question.
Signature
Task<DecorationT> Oculus.Interaction.ValueToClassDecorator< InstanceT, DecorationT >.GetDecorationAsync(InstanceT instance)
Parameters
instance: InstanceT  The instance for which to retrieve the decoration
Returns
Task< DecorationT >  A task resulting in the decoration associated with instance
RemoveDecoration ( instance )
Removes the association between an instance and a decoration.
If this instance had no decoration, this does nothing. If a decoration was removed, note that GetDecorationAsync(InstanceT) will resume returning uncompleted tasks for this instance, which will be completed if and when the instance is decorated again.
Signature
void Oculus.Interaction.ValueToClassDecorator< InstanceT, DecorationT >.RemoveDecoration(InstanceT instance)
Parameters
instance: InstanceT  The instance from which decoration should be removed
Returns
void
TryGetDecoration ( instance , decoration )
Synchronously retrieves the decoration associated with an instance, if one is available.
Signature
bool Oculus.Interaction.ValueToClassDecorator< InstanceT, DecorationT >.TryGetDecoration(InstanceT instance, out DecorationT decoration)
Parameters
instance: InstanceT  The instance for which to retrieve the decoration
decoration: out DecorationT  Out parameter to be populated with the decoration if one exists, otherwise null
Returns
bool  True if decoration was populated with a valid decoration, otherwise false