Class AdapterManager
Adapter manager is a class that manages the registration and retrieval of adapters. It can be used to manager specific unity code that may change between versions by creating a compiled interface and an open-source implementation.
Namespace: Xareus.Unity.Utils.Adapters
Assembly: Xareus.Unity.Utils.dll
Syntax
public static class AdapterManager
Methods
AutoRegisterAdapters()
Automatically discovers and registers all adapters marked with [AutoRegisterAdapter]. This method scans all loaded assemblies for adapter implementations.
Declaration
public static void AutoRegisterAdapters()
GetAdapter(string)
Retrieves an adapter by its name. Returns null if no adapter is found.
Declaration
public static IAdapter GetAdapter(string adapterName)
Parameters
| Type | Name | Description |
|---|---|---|
| string | adapterName | The name of the adapter to retrieve. |
Returns
| Type | Description |
|---|---|
| IAdapter | The adapter instance, or null if not found. |
GetAdapter<T>()
Retrieves an adapter by its interface type. Returns null if no adapter is found.
Declaration
public static T GetAdapter<T>() where T : class, IAdapter
Returns
| Type | Description |
|---|---|
| T | The adapter instance, or null if not found. |
Type Parameters
| Name | Description |
|---|---|
| T | The adapter interface type. |
HasAdapter(string)
Checks if an adapter is registered.
Declaration
public static bool HasAdapter(string adapterName)
Parameters
| Type | Name | Description |
|---|---|---|
| string | adapterName | The name of the adapter. |
Returns
| Type | Description |
|---|---|
| bool | True if the adapter is registered, false otherwise. |
HasAdapter<T>()
Checks if an adapter is registered.
Declaration
public static bool HasAdapter<T>() where T : class, IAdapter
Returns
| Type | Description |
|---|---|
| bool | True if the adapter is registered, false otherwise. |
Type Parameters
| Name | Description |
|---|---|
| T | The adapter interface type. |
RegisterAdapter(IAdapter)
Registers an adapter with the manager. If an adapter with the same name already exists, it will be replaced.
Declaration
public static void RegisterAdapter(IAdapter adapter)
Parameters
| Type | Name | Description |
|---|---|---|
| IAdapter | adapter | The adapter to register. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown if adapter is null. |
RegisterAdapterFromType(Type)
Declaration
public static void RegisterAdapterFromType(Type adapterType)
Parameters
| Type | Name | Description |
|---|---|---|
| Type | adapterType |
Events
OnAdapterRegistered
Event raised when an adapter is registered.
Declaration
public static event EventHandler<IAdapter> OnAdapterRegistered
Event Type
| Type | Description |
|---|---|
| EventHandler<IAdapter> |