Add new functions to extension system.
This commit is contained in:
parent
c4fe4841fe
commit
9ee6c1180d
@ -108,6 +108,11 @@ namespace Dashboard.Pal
|
|||||||
return _extensions.Contains<T>() || _preloadedExtensions.Contains<T>();
|
return _extensions.Contains<T>() || _preloadedExtensions.Contains<T>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool ExtensionPreload<T>(Func<IApplicationExtension> loader) where T : IApplicationExtension
|
||||||
|
{
|
||||||
|
return _preloadedExtensions.Add<T>(loader);
|
||||||
|
}
|
||||||
|
|
||||||
public bool ExtensionPreload<T>() where T : IApplicationExtension, new()
|
public bool ExtensionPreload<T>() where T : IApplicationExtension, new()
|
||||||
{
|
{
|
||||||
return _preloadedExtensions.Add<T>(() => new T());
|
return _preloadedExtensions.Add<T>(() => new T());
|
||||||
@ -131,8 +136,7 @@ namespace Dashboard.Pal
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
extension = (T?)typeof(T).GetConstructor(BindingFlags.Public, [])?.Invoke([]) ??
|
extension = Activator.CreateInstance<T>();
|
||||||
throw new Exception("Constructor not found.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_extensions.Add(extension);
|
_extensions.Add(extension);
|
||||||
@ -142,6 +146,15 @@ namespace Dashboard.Pal
|
|||||||
return extension;
|
return extension;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool ExtensionLoad<T>(T instance) where T : IApplicationExtension
|
||||||
|
{
|
||||||
|
if (_extensions.Contains(instance))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
_extensions.Add(instance);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
protected virtual void Dispose(bool isDisposing)
|
protected virtual void Dispose(bool isDisposing)
|
||||||
{
|
{
|
||||||
if (!isDisposing) return;
|
if (!isDisposing) return;
|
||||||
|
|||||||
@ -10,7 +10,7 @@ namespace Dashboard.Pal
|
|||||||
private readonly TypeDictionary<IDeviceContextExtension, Func<IDeviceContextExtension>> _preloadedExtensions =
|
private readonly TypeDictionary<IDeviceContextExtension, Func<IDeviceContextExtension>> _preloadedExtensions =
|
||||||
new TypeDictionary<IDeviceContextExtension, Func<IDeviceContextExtension>>(true);
|
new TypeDictionary<IDeviceContextExtension, Func<IDeviceContextExtension>>(true);
|
||||||
|
|
||||||
private Dictionary<string, object> _attributes = new Dictionary<string, object>();
|
private readonly Dictionary<string, object> _attributes = new Dictionary<string, object>();
|
||||||
|
|
||||||
|
|
||||||
public abstract string DriverName { get; }
|
public abstract string DriverName { get; }
|
||||||
@ -40,6 +40,11 @@ namespace Dashboard.Pal
|
|||||||
return _extensions.Contains<T>() || _preloadedExtensions.Contains<T>();
|
return _extensions.Contains<T>() || _preloadedExtensions.Contains<T>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool ExtensionPreload<T>(Func<IDeviceContextExtension> loader) where T : IDeviceContextExtension
|
||||||
|
{
|
||||||
|
return _preloadedExtensions.Add<T>(loader);
|
||||||
|
}
|
||||||
|
|
||||||
public bool ExtensionPreload<T>() where T : IDeviceContextExtension, new()
|
public bool ExtensionPreload<T>() where T : IDeviceContextExtension, new()
|
||||||
{
|
{
|
||||||
return _preloadedExtensions.Add<T>(() => new T());
|
return _preloadedExtensions.Add<T>(() => new T());
|
||||||
@ -63,9 +68,7 @@ namespace Dashboard.Pal
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
extension =(T)(
|
extension = Activator.CreateInstance<T>();
|
||||||
typeof(T).GetConstructor(BindingFlags.Public, []) ?.Invoke([])
|
|
||||||
?? throw new Exception("Could not find a suitable constructor for the given extension."));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_extensions.Add(extension);
|
_extensions.Add(extension);
|
||||||
@ -75,6 +78,15 @@ namespace Dashboard.Pal
|
|||||||
return extension;
|
return extension;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool ExtensionLoad<T>(T instance) where T : IDeviceContextExtension
|
||||||
|
{
|
||||||
|
if (_extensions.Contains(instance))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
_extensions.Add(instance);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
public void SetAttribute(string name, object? v)
|
public void SetAttribute(string name, object? v)
|
||||||
{
|
{
|
||||||
if (v != null)
|
if (v != null)
|
||||||
|
|||||||
@ -58,12 +58,31 @@ namespace Dashboard.Pal
|
|||||||
/// </returns>
|
/// </returns>
|
||||||
bool ExtensionPreload<T>() where T : TExtension, new();
|
bool ExtensionPreload<T>() where T : TExtension, new();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Preload extensions, to be lazy loaded when required.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="loader">The loader delegate.</param>
|
||||||
|
/// <typeparam name="T">The extension to preload.</typeparam>
|
||||||
|
/// <returns>
|
||||||
|
/// True if the extension was added to the preload set. Otherwise, already loaded or another extension
|
||||||
|
/// exists which provides this.
|
||||||
|
/// </returns>
|
||||||
|
bool ExtensionPreload<T>(Func<TExtension> loader) where T : TExtension;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Require an extension.
|
/// Require an extension.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <typeparam name="T">The extension to require.</typeparam>
|
/// <typeparam name="T">The extension to require.</typeparam>
|
||||||
/// <returns>The extension instance.</returns>
|
/// <returns>The extension instance.</returns>
|
||||||
T ExtensionRequire<T>() where T : TExtension;
|
T ExtensionRequire<T>() where T : TExtension;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Load an extension.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="instance">The extension instance.</param>
|
||||||
|
/// <typeparam name="T">The extension to require.</typeparam>
|
||||||
|
/// <returns>True if the extension was loaded, false if there was already one.</returns>
|
||||||
|
bool ExtensionLoad<T>(T instance) where T : TExtension;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user