mirror of
https://github.com/DarthAffe/RGB.NET.git
synced 2025-12-13 01:58:30 +00:00
Merge pull request #235 from DarthAffe/SmallImprovements
Small improvements
This commit is contained in:
commit
5fc2e34f28
@ -14,7 +14,7 @@ namespace RGB.NET.Core
|
||||
private readonly List<T> _decorators = new();
|
||||
|
||||
/// <inheritdoc />
|
||||
public IReadOnlyCollection<T> Decorators { get; }
|
||||
public IReadOnlyList<T> Decorators { get; }
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
@ -20,7 +20,7 @@ namespace RGB.NET.Core
|
||||
/// <summary>
|
||||
/// Gets a readonly-list of all <see cref="IDecorator"/> attached to this <see cref="IDecoratable{T}"/>.
|
||||
/// </summary>
|
||||
IReadOnlyCollection<T> Decorators { get; }
|
||||
IReadOnlyList<T> Decorators { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Adds an <see cref="IDecorator"/> to the <see cref="IDecoratable"/>.
|
||||
|
||||
@ -30,7 +30,7 @@ namespace RGB.NET.Core
|
||||
protected Dictionary<int, IDeviceUpdateTrigger> UpdateTriggerMapping { get; } = new();
|
||||
|
||||
/// <inheritdoc />
|
||||
public ReadOnlyCollection<(int id, IDeviceUpdateTrigger trigger)> UpdateTriggers => new(UpdateTriggerMapping.Select(x => (x.Key, x.Value)).ToList());
|
||||
public IReadOnlyList<(int id, IDeviceUpdateTrigger trigger)> UpdateTriggers => new ReadOnlyCollection<(int id, IDeviceUpdateTrigger trigger)>(UpdateTriggerMapping.Select(x => (x.Key, x.Value)).ToList());
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
@ -2,7 +2,6 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
namespace RGB.NET.Core
|
||||
{
|
||||
@ -31,7 +30,7 @@ namespace RGB.NET.Core
|
||||
/// <summary>
|
||||
/// Gets a collection <see cref="IDeviceUpdateTrigger"/> registered to this device provider.
|
||||
/// </summary>
|
||||
ReadOnlyCollection<(int id, IDeviceUpdateTrigger trigger)> UpdateTriggers { get; }
|
||||
IReadOnlyList<(int id, IDeviceUpdateTrigger trigger)> UpdateTriggers { get; }
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
@ -26,20 +26,15 @@ namespace RGB.NET.Core
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly list containing all loaded <see cref="IRGBDevice"/>.
|
||||
/// This collection should be locked when enumerated in a multi-threaded application.
|
||||
/// </summary>
|
||||
public IEnumerable<IRGBDevice> Devices
|
||||
{
|
||||
get
|
||||
{
|
||||
lock (_devices)
|
||||
return new ReadOnlyCollection<IRGBDevice>(_devices);
|
||||
}
|
||||
}
|
||||
public IReadOnlyList<IRGBDevice> Devices { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly list containing all registered <see cref="IUpdateTrigger"/>.
|
||||
/// This collection should be locked when enumerated in a multi-threaded application.
|
||||
/// </summary>
|
||||
public IEnumerable<IUpdateTrigger> UpdateTriggers => new ReadOnlyCollection<IUpdateTrigger>(_updateTriggers);
|
||||
public IReadOnlyList<IUpdateTrigger> UpdateTriggers { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a copy of the <see cref="Rectangle"/> representing this <see cref="RGBSurface"/>.
|
||||
@ -53,7 +48,7 @@ namespace RGB.NET.Core
|
||||
{
|
||||
get
|
||||
{
|
||||
lock (_devices)
|
||||
lock (Devices)
|
||||
return _devices.SelectMany(x => x);
|
||||
}
|
||||
}
|
||||
@ -124,6 +119,9 @@ namespace RGB.NET.Core
|
||||
public RGBSurface()
|
||||
{
|
||||
_deltaTimeCounter = Stopwatch.StartNew();
|
||||
|
||||
Devices = new ReadOnlyCollection<IRGBDevice>(_devices);
|
||||
UpdateTriggers = new ReadOnlyCollection<IUpdateTrigger>(_updateTriggers);
|
||||
}
|
||||
|
||||
#endregion
|
||||
@ -146,8 +144,8 @@ namespace RGB.NET.Core
|
||||
bool render = customData["render"] as bool? ?? true;
|
||||
bool updateDevices = customData["updateDevices"] as bool? ?? true;
|
||||
|
||||
lock (_updateTriggers)
|
||||
lock (_devices)
|
||||
lock (UpdateTriggers)
|
||||
lock (Devices)
|
||||
{
|
||||
OnUpdating(updateTrigger, customData);
|
||||
|
||||
@ -178,7 +176,7 @@ namespace RGB.NET.Core
|
||||
public void Dispose()
|
||||
{
|
||||
List<IRGBDevice> devices;
|
||||
lock (_devices)
|
||||
lock (Devices)
|
||||
devices = new List<IRGBDevice>(_devices);
|
||||
|
||||
foreach (IRGBDevice device in devices)
|
||||
@ -267,7 +265,7 @@ namespace RGB.NET.Core
|
||||
/// <param name="device">The <see cref="IRGBDevice"/> to attach.</param>
|
||||
public void Attach(IRGBDevice device)
|
||||
{
|
||||
lock (_devices)
|
||||
lock (Devices)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(device.DeviceInfo.DeviceName)) throw new RGBDeviceException($"The device '{device.DeviceInfo.Manufacturer} {device.DeviceInfo.Model}' has no valid name.");
|
||||
if (device.Surface != null) throw new RGBSurfaceException($"The device '{device.DeviceInfo.DeviceName}' is already attached to a surface.");
|
||||
@ -287,7 +285,7 @@ namespace RGB.NET.Core
|
||||
/// <returns><c>true</c> if the <see cref="IRGBDevice"/> could be detached; <c>false</c> otherwise.</returns>
|
||||
public void Detach(IRGBDevice device)
|
||||
{
|
||||
lock (_devices)
|
||||
lock (Devices)
|
||||
{
|
||||
if (!_devices.Contains(device)) throw new RGBSurfaceException($"The device '{device.DeviceInfo.DeviceName}' is not attached to this surface.");
|
||||
|
||||
@ -314,7 +312,7 @@ namespace RGB.NET.Core
|
||||
|
||||
private void UpdateSurfaceRectangle()
|
||||
{
|
||||
lock (_devices)
|
||||
lock (Devices)
|
||||
{
|
||||
Rectangle devicesRectangle = new(_devices.Select(d => d.Boundary));
|
||||
Boundary = Boundary.SetSize(new Size(devicesRectangle.Location.X + devicesRectangle.Size.Width, devicesRectangle.Location.Y + devicesRectangle.Size.Height));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user