Show / Hide Table of Contents

Class ObjectPoolExtensions

Extension methods for IObjectPool<T> instances.

Inheritance
System.Object
ObjectPoolExtensions
Namespace: Eco.Shared.Pools
Assembly: Eco.Shared.dll
Syntax
public static class ObjectPoolExtensions : Object

Methods

AsService<T>(IObjectPool<T>, Action<T>)

Wraps pool with PoolService<T> with default constructor for new pool elements and optional onReturn cleanup method. With this factory method

new PoolService<MyClass>(new MyPool<MyClass>(), () => new MyClass(), onReturn)
can be rewritten as
new MyPool<MyClass>().AsService(onReturn)
.

Declaration
public static PoolService<T> AsService<T>(this IObjectPool<T> pool, Action<T> onReturn = null)
    where T : class, new()
Parameters
Type Name Description
IObjectPool<T> pool
System.Action<T> onReturn
Returns
Type Description
PoolService<T>
Type Parameters
Name Description
T

AsService<T>(IObjectPool<T>, Func<T>, Action<T>)

Wraps pool with PoolService<T> with factory for new pool elements and optional onReturn cleanup method. With this factory method

new PoolService<MyClass>(new MyPool<MyClass>(), () => new MyClass("abc"))
can be rewritten as
new MyPool<MyClass>().AsService(() => new MyClass("abc"))
.

Declaration
public static PoolService<T> AsService<T>(this IObjectPool<T> pool, Func<T> factory, Action<T> onReturn = null)
    where T : class
Parameters
Type Name Description
IObjectPool<T> pool
System.Func<T> factory
System.Action<T> onReturn
Returns
Type Description
PoolService<T>
Type Parameters
Name Description
T
☀
☾
In This Article
Back to top
Copyright (c) Strange Loop Games 2021
☀
☾