Struct ComponentHandle
A handle to a component of any type. Useful to avoid boxing.
public readonly struct ComponentHandle : IEquatable<ComponentHandle>, IDisposable
- Implements
- Inherited Members
Remarks
Must be disposed. The handle must also not be used afterwards.
Properties
ComponentID
The ComponentID of the component represented by this ComponentHandle.
public ComponentID ComponentID { get; }
Property Value
Type
The type of component represented by this ComponentHandle.
public Type Type { get; }
Property Value
Methods
CreateFromBoxed(ComponentID, object)
Creates a new ComponentHandle from a potentially boxed component.
public static ComponentHandle CreateFromBoxed(ComponentID typeAs, object @object)
Parameters
typeAsComponentIDThe type to store the component as.
objectobjectThe potentially boxed component to store.
Returns
- ComponentHandle
A ComponentHandle instance that can be used to retrieve
object.
Exceptions
- InvalidCastException
objectis not oftypeAs.Type.Type
CreateFromBoxed(object)
Creates a new ComponentHandle from a potentially boxed component.
public static ComponentHandle CreateFromBoxed(object @object)
Parameters
objectobjectThe potentially boxed component to store.
Returns
- ComponentHandle
A ComponentHandle instance that can be used to retrieve
object.
Create<T>(in T)
Creates a new ComponentHandle from a component.
public static ComponentHandle Create<T>(in T comp)
Parameters
compTThe component to store.
Returns
- ComponentHandle
A ComponentHandle instance that can be used to retrieve
comp.
Type Parameters
TThe type of component to store.
Dispose()
Frees the memory associated with this component handle and marks it for reuse.
public void Dispose()
Remarks
It is very easy to leak memory by improperly disposing of ComponentHandle instances. The handle does not check for double disposes.
Equals(ComponentHandle)
Checks if a ComponentHandle is equal to this handle and so points to the same component.
public bool Equals(ComponentHandle other)
Parameters
otherComponentHandleThe ComponentHandle to compare to.
Returns
Equals(object?)
Checks if an object is equal to this component handle and points to the same component.
public override bool Equals(object? obj)
Parameters
objobjectThe object to check.
Returns
GetHashCode()
The hashcode.
public override int GetHashCode()
Returns
- int
The hashcode -_-.
RetrieveBoxed()
Gets the value of the component represented bu this ComponentHandle, boxing if needed.
public object RetrieveBoxed()
Returns
- object
The component value.
Retrieve<T>()
Gets the value of this component strongly typed.
public T Retrieve<T>()
Returns
- T
The component value.
Type Parameters
TThe type of the component. ID should be equal to ComponentID
Operators
operator ==(ComponentHandle, ComponentHandle)
Checks if two component handles point to the same component.
public static bool operator ==(ComponentHandle left, ComponentHandle right)
Parameters
leftComponentHandleThe first component handle.
rightComponentHandleThe second component handle.
Returns
operator !=(ComponentHandle, ComponentHandle)
Checks if two component handles do not point to the same component.
public static bool operator !=(ComponentHandle left, ComponentHandle right)
Parameters
leftComponentHandleThe first component handle.
rightComponentHandleThe second component handle.