Moved extension classes to seperate files as Jimmacle requires.
This commit is contained in:
30
Torch.API/Managers/DependencyManagerExtensions.cs
Normal file
30
Torch.API/Managers/DependencyManagerExtensions.cs
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Torch.API.Managers
|
||||||
|
{
|
||||||
|
public static class DependencyManagerExtensions
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Removes a single manager from this dependency manager.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="managerType">The dependency type to remove</param>
|
||||||
|
/// <returns>The manager that was removed, or null if one wasn't removed</returns>
|
||||||
|
/// <exception cref="InvalidOperationException">When removing managers from an initialized dependency manager</exception>
|
||||||
|
public static IManager RemoveManager(this IDependencyManager depManager, Type managerType)
|
||||||
|
{
|
||||||
|
IManager mgr = depManager.GetManager(managerType);
|
||||||
|
return depManager.RemoveManager(mgr) ? mgr : null;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Removes a single manager from this dependency manager.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T">The dependency type to remove</typeparam>
|
||||||
|
/// <returns>The manager that was removed, or null if one wasn't removed</returns>
|
||||||
|
/// <exception cref="InvalidOperationException">When removing managers from an initialized dependency manager</exception>
|
||||||
|
public static IManager RemoveManager<T>(this IDependencyManager depManager)
|
||||||
|
{
|
||||||
|
return depManager.RemoveManager(typeof(T));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
15
Torch.API/Managers/DependencyProviderExtensions.cs
Normal file
15
Torch.API/Managers/DependencyProviderExtensions.cs
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
namespace Torch.API.Managers
|
||||||
|
{
|
||||||
|
public static class DependencyProviderExtensions
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the manager that provides the given type. If there is no such manager, returns null.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T">Type of manager</typeparam>
|
||||||
|
/// <returns>manager, or null if none exists</returns>
|
||||||
|
public static T GetManager<T>(this IDependencyProvider depProvider) where T : class, IManager
|
||||||
|
{
|
||||||
|
return (T)depProvider.GetManager(typeof(T));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -59,30 +59,4 @@ namespace Torch.API.Managers
|
|||||||
/// <exception cref="InvalidOperationException">When trying to determine unload order before this dependency manager is initialized</exception>
|
/// <exception cref="InvalidOperationException">When trying to determine unload order before this dependency manager is initialized</exception>
|
||||||
IEnumerable<IManager> UnloadOrder { get; }
|
IEnumerable<IManager> UnloadOrder { get; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class DependencyManagerExtensions
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Removes a single manager from this dependency manager.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="managerType">The dependency type to remove</param>
|
|
||||||
/// <returns>The manager that was removed, or null if one wasn't removed</returns>
|
|
||||||
/// <exception cref="InvalidOperationException">When removing managers from an initialized dependency manager</exception>
|
|
||||||
public static IManager RemoveManager(this IDependencyManager depManager, Type managerType)
|
|
||||||
{
|
|
||||||
IManager mgr = depManager.GetManager(managerType);
|
|
||||||
return depManager.RemoveManager(mgr) ? mgr : null;
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// Removes a single manager from this dependency manager.
|
|
||||||
/// </summary>
|
|
||||||
/// <typeparam name="T">The dependency type to remove</typeparam>
|
|
||||||
/// <returns>The manager that was removed, or null if one wasn't removed</returns>
|
|
||||||
/// <exception cref="InvalidOperationException">When removing managers from an initialized dependency manager</exception>
|
|
||||||
public static IManager RemoveManager<T>(this IDependencyManager depManager)
|
|
||||||
{
|
|
||||||
return depManager.RemoveManager(typeof(T));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -15,18 +15,4 @@ namespace Torch.API.Managers
|
|||||||
/// <returns>manager, or null if none exists</returns>
|
/// <returns>manager, or null if none exists</returns>
|
||||||
IManager GetManager(Type type);
|
IManager GetManager(Type type);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class DependencyProviderExtensions
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the manager that provides the given type. If there is no such manager, returns null.
|
|
||||||
/// </summary>
|
|
||||||
/// <typeparam name="T">Type of manager</typeparam>
|
|
||||||
/// <returns>manager, or null if none exists</returns>
|
|
||||||
public static T GetManager<T>(this IDependencyProvider depProvider) where T : class, IManager
|
|
||||||
{
|
|
||||||
return (T)depProvider.GetManager(typeof(T));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -157,6 +157,8 @@
|
|||||||
<Compile Include="ConnectionState.cs" />
|
<Compile Include="ConnectionState.cs" />
|
||||||
<Compile Include="IChatMessage.cs" />
|
<Compile Include="IChatMessage.cs" />
|
||||||
<Compile Include="ITorchConfig.cs" />
|
<Compile Include="ITorchConfig.cs" />
|
||||||
|
<Compile Include="Managers\DependencyManagerExtensions.cs" />
|
||||||
|
<Compile Include="Managers\DependencyProviderExtensions.cs" />
|
||||||
<Compile Include="Managers\IDependencyManager.cs" />
|
<Compile Include="Managers\IDependencyManager.cs" />
|
||||||
<Compile Include="Managers\IDependencyProvider.cs" />
|
<Compile Include="Managers\IDependencyProvider.cs" />
|
||||||
<Compile Include="Managers\IManager.cs" />
|
<Compile Include="Managers\IManager.cs" />
|
||||||
|
Reference in New Issue
Block a user