Table of Contents

Struct ComponentHandle

Namespace
Frent.Core
Assembly
Frent.dll

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

ComponentID

Type

The type of component represented by this ComponentHandle.

public Type Type { get; }

Property Value

Type

Methods

CreateFromBoxed(ComponentID, object)

Creates a new ComponentHandle from a potentially boxed component.

public static ComponentHandle CreateFromBoxed(ComponentID typeAs, object @object)

Parameters

typeAs ComponentID

The type to store the component as.

object object

The potentially boxed component to store.

Returns

ComponentHandle

A ComponentHandle instance that can be used to retrieve object.

Exceptions

InvalidCastException

object is not of typeAs.Type.Type

CreateFromBoxed(object)

Creates a new ComponentHandle from a potentially boxed component.

public static ComponentHandle CreateFromBoxed(object @object)

Parameters

object object

The 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

comp T

The component to store.

Returns

ComponentHandle

A ComponentHandle instance that can be used to retrieve comp.

Type Parameters

T

The 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

other ComponentHandle

The ComponentHandle to compare to.

Returns

bool

true when they are equal, false otherwise.

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

obj object

The object to check.

Returns

bool

true when they are equal, false otherwise.

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

T

The 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

left ComponentHandle

The first component handle.

right ComponentHandle

The second component handle.

Returns

bool

true when they are equal, false otherwise.

operator !=(ComponentHandle, ComponentHandle)

Checks if two component handles do not point to the same component.

public static bool operator !=(ComponentHandle left, ComponentHandle right)

Parameters

left ComponentHandle

The first component handle.

right ComponentHandle

The second component handle.

Returns

bool

true when they are not equal, false otherwise.