Class ComponentBaseExtensions
Extensions for IComponent.
public static class ComponentBaseExtensions
- Inheritance
-
objectComponentBaseExtensions
Methods
DisposeBy<T>(T, ICollectorHolder)
Keeps a disposable object alive by adding it to a container.
public static T? DisposeBy<T>(this T component, ICollectorHolder container) where T : IDisposable
Parameters
componentTThe Component to keep alive.
containerICollectorHolderThe container that will keep a reference to the Component.
Returns
- T
The same Component instance.
Type Parameters
TThe type of the Component.
KeepReference<T>(T)
Pins this component as a new reference.
public static T? KeepReference<T>(this T component) where T : IReferencable
Parameters
componentTThe Component to add a reference to.
Returns
- T
The same Component instance.
Type Parameters
TThe type of the Component.
Remarks
This method is equivalent to calling AddReference() and returning the
same component instance.
PushTagAndRestore<T>(ComponentBase, PropertyKey<T?>, T)
Sets a tag in a Component and removes it after using it.
public static ComponentBaseExtensions.PropertyTagRestore<T> PushTagAndRestore<T>(this ComponentBase component, PropertyKey<T?> key, T value)
Parameters
componentComponentBaseThe Component to set a tag for.
keyPropertyKey<T>The key to identify the tag to set.
valueTThe value of the tag.
Returns
- ComponentBaseExtensions.PropertyTagRestore<T>
A ComponentBaseExtensions.PropertyTagRestore<T> structure that can be used with a using clause (or manually disposed) to set a tag, perform some action, and remove the tag once finished.
Type Parameters
TThe type of the tag.
Remarks
This method is used to set a property value in Tags, perform some actions, and restore the previous value after finishing.
The returned object must be disposed once the original value must be restored. It can be done manually (by calling Dispose()) or automatically with a using clause.
ReleaseBy<T>(T, ICollectorHolder)
Keeps a referenceable object alive by adding it to a container.
public static T? ReleaseBy<T>(this T component, ICollectorHolder container) where T : IReferencable
Parameters
componentTThe Component to keep alive.
containerICollectorHolderThe container that will keep a reference to the Component.
Returns
- T
The same Component instance.
Type Parameters
TThe type of the Component.
RemoveDisposeBy<T>(T, ICollectorHolder)
Removes a disposable object from a container that keeping it alive.
public static void RemoveDisposeBy<T>(this T component, ICollectorHolder container) where T : IDisposable
Parameters
componentTThe Component to remove.
containerICollectorHolderThe container that kept a reference to the Component.
Type Parameters
TThe type of the Component.
RemoveReleaseBy<T>(T, ICollectorHolder)
Removes a referenceable object from a container that keeping it alive.
public static void RemoveReleaseBy<T>(this T component, ICollectorHolder container) where T : IReferencable
Parameters
componentTThe Component to remove.
containerICollectorHolderThe container that kept a reference to the Component.
Type Parameters
TThe type of the Component.