Skip to content

Commit

Permalink
Merge pull request #362 from DarthAffe/Core/CodeStyling
Browse files Browse the repository at this point in the history
Applied some C#12 stuff
  • Loading branch information
DarthAffe authored Dec 31, 2023
2 parents 2796acd + aeab930 commit 79f71ba
Show file tree
Hide file tree
Showing 109 changed files with 357 additions and 448 deletions.
2 changes: 1 addition & 1 deletion RGB.NET.Core/Decorators/AbstractDecorateable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public abstract class AbstractDecoratable<T> : AbstractBindable, IDecoratable<T>
{
#region Properties & Fields

private readonly List<T> _decorators = new();
private readonly List<T> _decorators = [];

/// <inheritdoc />
public IReadOnlyList<T> Decorators { get; }
Expand Down
6 changes: 3 additions & 3 deletions RGB.NET.Core/Decorators/AbstractDecorator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public int Order
/// <summary>
/// Gets a readonly-list of all <see cref="IDecoratable"/> this decorator is attached to.
/// </summary>
protected List<IDecoratable> DecoratedObjects { get; } = new();
protected List<IDecoratable> DecoratedObjects { get; } = [];

#endregion

Expand All @@ -46,14 +46,14 @@ public int Order
/// </summary>
protected virtual void Detach()
{
List<IDecoratable> decoratables = new(DecoratedObjects);
List<IDecoratable> decoratables = [..DecoratedObjects];
foreach (IDecoratable decoratable in decoratables)
{
IEnumerable<Type> types = decoratable.GetType().GetInterfaces().Where(t => t.IsGenericType
&& (t.Name == typeof(IDecoratable<>).Name)
&& t.GenericTypeArguments[0].IsInstanceOfType(this));
foreach (Type decoratableType in types)
decoratableType.GetMethod(nameof(IDecoratable<IDecorator>.RemoveDecorator))?.Invoke(decoratable, new object[] { this });
decoratableType.GetMethod(nameof(IDecoratable<IDecorator>.RemoveDecorator))?.Invoke(decoratable, [this]);
}
}

Expand Down
3 changes: 1 addition & 2 deletions RGB.NET.Core/Decorators/IDecoratable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ namespace RGB.NET.Core;
/// <summary>
/// Represents a basic decoratable.
/// </summary>
public interface IDecoratable : INotifyPropertyChanged
{ }
public interface IDecoratable : INotifyPropertyChanged;

/// <inheritdoc />
/// <summary>
Expand Down
3 changes: 1 addition & 2 deletions RGB.NET.Core/Decorators/ILedGroupDecorator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@
/// <summary>
/// Represents a basic decorator decorating a <see cref="T:RGB.NET.Core.ILedGroup" />.
/// </summary>
public interface ILedGroupDecorator : IDecorator
{ }
public interface ILedGroupDecorator : IDecorator;
2 changes: 1 addition & 1 deletion RGB.NET.Core/Devices/AbstractRGBDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public abstract class AbstractRGBDevice<TDeviceInfo> : Placeable, IRGBDevice<TDe
/// <summary>
/// Gets a dictionary containing all <see cref="Led"/> of the <see cref="IRGBDevice"/>.
/// </summary>
protected Dictionary<LedId, Led> LedMapping { get; } = new();
protected Dictionary<LedId, Led> LedMapping { get; } = [];

/// <summary>
/// Gets the update queue used to update this device.
Expand Down
8 changes: 4 additions & 4 deletions RGB.NET.Core/Devices/AbstractRGBDeviceProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public abstract class AbstractRGBDeviceProvider : IRGBDeviceProvider
/// <summary>
/// The list of devices managed by this device-provider.
/// </summary>
protected List<IRGBDevice> InternalDevices { get; } = new();
protected List<IRGBDevice> InternalDevices { get; } = [];

/// <inheritdoc />
public virtual IReadOnlyList<IRGBDevice> Devices => new ReadOnlyCollection<IRGBDevice>(InternalDevices);
Expand All @@ -34,7 +34,7 @@ public abstract class AbstractRGBDeviceProvider : IRGBDeviceProvider
/// Gets the dictionary containing the registered update triggers.
/// Normally <see cref="UpdateTriggers"/> should be used to access them.
/// </summary>
protected Dictionary<int, IDeviceUpdateTrigger> UpdateTriggerMapping { get; } = new();
protected Dictionary<int, IDeviceUpdateTrigger> UpdateTriggerMapping { get; } = [];

/// <inheritdoc />
public IReadOnlyList<(int id, IDeviceUpdateTrigger trigger)> UpdateTriggers => new ReadOnlyCollection<(int id, IDeviceUpdateTrigger trigger)>(UpdateTriggerMapping.Select(x => (x.Key, x.Value)).ToList());
Expand Down Expand Up @@ -116,7 +116,7 @@ protected virtual IEnumerable<IRGBDevice> GetLoadedDevices(RGBDeviceType loadFil
{
if (_isDisposed) throw new ObjectDisposedException(GetType().FullName);

List<IRGBDevice> devices = new();
List<IRGBDevice> devices = [];
foreach (IRGBDevice device in LoadDevices())
{
try
Expand Down Expand Up @@ -189,7 +189,7 @@ protected virtual void Reset()
foreach (IRGBDevice device in Devices)
device.Dispose();

List<IRGBDevice> devices = new(InternalDevices);
List<IRGBDevice> devices = [..InternalDevices];
foreach (IRGBDevice device in devices)
RemoveDevice(device);

Expand Down
3 changes: 1 addition & 2 deletions RGB.NET.Core/Devices/TypeInterfaces/ICooler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@
/// <summary>
/// Represents a cooler-device
/// </summary>
public interface ICooler : IRGBDevice
{ }
public interface ICooler : IRGBDevice;
3 changes: 1 addition & 2 deletions RGB.NET.Core/Devices/TypeInterfaces/IDRAM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@
/// <summary>
/// Represents a DRAM-device
/// </summary>
public interface IDRAM : IRGBDevice
{ }
public interface IDRAM : IRGBDevice;
3 changes: 1 addition & 2 deletions RGB.NET.Core/Devices/TypeInterfaces/IFan.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@
/// <summary>
/// represents a fan-device
/// </summary>
public interface IFan : IRGBDevice
{ }
public interface IFan : IRGBDevice;
3 changes: 1 addition & 2 deletions RGB.NET.Core/Devices/TypeInterfaces/IGameController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@
/// <summary>
/// Represents a gamecontroller-device
/// </summary>
public interface IGameController: IRGBDevice
{ }
public interface IGameController: IRGBDevice;
3 changes: 1 addition & 2 deletions RGB.NET.Core/Devices/TypeInterfaces/IGraphicsCard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@
/// <summary>
/// Represents a graphics-card-device
/// </summary>
public interface IGraphicsCard : IRGBDevice
{ }
public interface IGraphicsCard : IRGBDevice;
3 changes: 1 addition & 2 deletions RGB.NET.Core/Devices/TypeInterfaces/IHeadset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@
/// <summary>
/// Represents a headset-device
/// </summary>
public interface IHeadset : IRGBDevice
{ }
public interface IHeadset : IRGBDevice;
3 changes: 1 addition & 2 deletions RGB.NET.Core/Devices/TypeInterfaces/IHeadsetStand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@
/// <summary>
/// Represents a headset-stand-device
/// </summary>
public interface IHeadsetStand : IRGBDevice
{ }
public interface IHeadsetStand : IRGBDevice;
3 changes: 1 addition & 2 deletions RGB.NET.Core/Devices/TypeInterfaces/IKeypad.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@
/// <summary>
/// Represents a keypad-device
/// </summary>
public interface IKeypad : IRGBDevice
{ }
public interface IKeypad : IRGBDevice;
3 changes: 1 addition & 2 deletions RGB.NET.Core/Devices/TypeInterfaces/ILedMatrix.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@
/// <summary>
/// Represents a led-matrix-device
/// </summary>
public interface ILedMatrix : IRGBDevice
{ }
public interface ILedMatrix : IRGBDevice;
3 changes: 1 addition & 2 deletions RGB.NET.Core/Devices/TypeInterfaces/ILedStripe.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@
/// <summary>
/// Represents a led-stripe-device
/// </summary>
public interface ILedStripe : IRGBDevice
{ }
public interface ILedStripe : IRGBDevice;
3 changes: 1 addition & 2 deletions RGB.NET.Core/Devices/TypeInterfaces/IMainboard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@
/// <summary>
/// Represents a mainboard-device
/// </summary>
public interface IMainboard : IRGBDevice
{ }
public interface IMainboard : IRGBDevice;
3 changes: 1 addition & 2 deletions RGB.NET.Core/Devices/TypeInterfaces/IMouse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@
/// <summary>
/// Represents a mouse-device
/// </summary>
public interface IMouse : IRGBDevice
{ }
public interface IMouse : IRGBDevice;
3 changes: 1 addition & 2 deletions RGB.NET.Core/Devices/TypeInterfaces/IMousepad.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@
/// <summary>
/// Represents a mousepad-device
/// </summary>
public interface IMousepad : IRGBDevice
{ }
public interface IMousepad : IRGBDevice;
3 changes: 1 addition & 2 deletions RGB.NET.Core/Devices/TypeInterfaces/ISpeaker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@
/// <summary>
/// Represents a speaker-device
/// </summary>
public interface ISpeaker : IRGBDevice
{ }
public interface ISpeaker : IRGBDevice;
3 changes: 1 addition & 2 deletions RGB.NET.Core/Devices/TypeInterfaces/IUnknownDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@
/// <summary>
/// Represents a device with unkown or not specified type.
/// </summary>
public interface IUnknownDevice : IRGBDevice
{ }
public interface IUnknownDevice : IRGBDevice;
17 changes: 4 additions & 13 deletions RGB.NET.Core/Events/DevicesChangedEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,13 @@

namespace RGB.NET.Core;

public sealed class DevicesChangedEventArgs : EventArgs
public sealed class DevicesChangedEventArgs(IRGBDevice device, DevicesChangedEventArgs.DevicesChangedAction action)
: EventArgs
{
#region Properties & Fields

public IRGBDevice Device { get; }
public DevicesChangedAction Action { get; }

#endregion

#region Constructors

public DevicesChangedEventArgs(IRGBDevice device, DevicesChangedAction action)
{
this.Device = device;
this.Action = action;
}
public IRGBDevice Device { get; } = device;
public DevicesChangedAction Action { get; } = action;

#endregion

Expand Down
3 changes: 1 addition & 2 deletions RGB.NET.Core/Events/UpdatedEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@ namespace RGB.NET.Core;
/// <summary>
/// Represents the information supplied with an <see cref="E:RGB.NET.Core.RGBSurface.Updated" />-event.
/// </summary>
public class UpdatedEventArgs : EventArgs
{ }
public class UpdatedEventArgs : EventArgs;
13 changes: 7 additions & 6 deletions RGB.NET.Core/Extensions/RectangleExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,13 @@ public static bool Contains(this in Rectangle rect, in Rectangle rect2) => (rect
/// <returns>A array of <see cref="Point"/> containing the new locations of the corners of the original rectangle.</returns>
public static Point[] Rotate(this in Rectangle rect, in Rotation rotation, in Point origin = new())
{
Point[] points = {
rect.Location, // top left
new(rect.Location.X + rect.Size.Width, rect.Location.Y), // top right
new(rect.Location.X + rect.Size.Width, rect.Location.Y + rect.Size.Height), // bottom right
new(rect.Location.X, rect.Location.Y + rect.Size.Height), // bottom right
};
Point[] points =
[
rect.Location, // top left
new Point(rect.Location.X + rect.Size.Width, rect.Location.Y), // top right
new Point(rect.Location.X + rect.Size.Width, rect.Location.Y + rect.Size.Height), // bottom right
new Point(rect.Location.X, rect.Location.Y + rect.Size.Height), // bottom right
];

float sin = MathF.Sin(rotation.Radians);
float cos = MathF.Cos(rotation.Radians);
Expand Down
4 changes: 2 additions & 2 deletions RGB.NET.Core/Helper/TimerHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static bool UseHighResolutionTimers
}

// ReSharper disable once InconsistentNaming
private static readonly HashSet<HighResolutionTimerDisposable> _timerLeases = new();
private static readonly HashSet<HighResolutionTimerDisposable> _timerLeases = [];

#endregion

Expand Down Expand Up @@ -143,7 +143,7 @@ private static void DisableHighResolutionTimers()
/// </summary>
public static void DisposeAllHighResolutionTimerRequests()
{
List<HighResolutionTimerDisposable> timerLeases = new(_timerLeases);
List<HighResolutionTimerDisposable> timerLeases = [.._timerLeases];
foreach (HighResolutionTimerDisposable timer in timerLeases)
timer.Dispose();
}
Expand Down
10 changes: 5 additions & 5 deletions RGB.NET.Core/Ids/IdGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ public static class IdGenerator
#region Properties & Fields

// ReSharper disable InconsistentNaming
private static readonly HashSet<string> _registeredIds = new();
private static readonly Dictionary<Assembly, Dictionary<string, string>> _idMappings = new();
private static readonly Dictionary<Assembly, Dictionary<string, int>> _counter = new();
private static readonly HashSet<string> _registeredIds = [];
private static readonly Dictionary<Assembly, Dictionary<string, string>> _idMappings = [];
private static readonly Dictionary<Assembly, Dictionary<string, int>> _counter = [];
// ReSharper restore InconsistentNaming

#endregion
Expand All @@ -33,8 +33,8 @@ internal static string MakeUnique(Assembly callingAssembly, string id)
{
if (!_idMappings.TryGetValue(callingAssembly, out Dictionary<string, string>? idMapping))
{
_idMappings.Add(callingAssembly, idMapping = new Dictionary<string, string>());
_counter.Add(callingAssembly, new Dictionary<string, int>());
_idMappings.Add(callingAssembly, idMapping = []);
_counter.Add(callingAssembly, []);
}

Dictionary<string, int> counterMapping = _counter[callingAssembly];
Expand Down
6 changes: 3 additions & 3 deletions RGB.NET.Core/Leds/LedMapping.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ public sealed class LedMapping<T> : IEnumerable<(LedId ledId, T mapping)>
{
#region Constants

public static LedMapping<T> Empty { get; } = new();
public static LedMapping<T> Empty { get; } = [];

#endregion

#region Properties & Fields

private readonly Dictionary<LedId, T> _mapping = new();
private readonly Dictionary<T, LedId> _reverseMapping = new();
private readonly Dictionary<LedId, T> _mapping = [];
private readonly Dictionary<T, LedId> _reverseMapping = [];

/// <summary>
/// Gets the number of entries in this mapping.
Expand Down
3 changes: 1 addition & 2 deletions RGB.NET.Core/MVVM/IBindable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ namespace RGB.NET.Core;
/// <summary>
/// Represents a basic bindable class which notifies when a property value changes.
/// </summary>
public interface IBindable : INotifyPropertyChanged
{ }
public interface IBindable : INotifyPropertyChanged;
2 changes: 1 addition & 1 deletion RGB.NET.Core/Misc/AbstractReferenceCounting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public abstract class AbstractReferenceCounting : IReferenceCounting
{
#region Properties & Fields

private readonly HashSet<object> _referencingObjects = new();
private readonly HashSet<object> _referencingObjects = [];

/// <inheritdoc />
public int ActiveReferenceCount
Expand Down
19 changes: 2 additions & 17 deletions RGB.NET.Core/Misc/ActionDisposable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,11 @@

namespace RGB.NET.Core;

public sealed class ActionDisposable : IDisposable
public sealed class ActionDisposable(Action onDispose) : IDisposable
{
#region Properties & Fields

private readonly Action _onDispose;

#endregion

#region Constructors

public ActionDisposable(Action onDispose)
{
this._onDispose = onDispose;
}

#endregion

#region Methods

public void Dispose() => _onDispose();
public void Dispose() => onDispose();

#endregion
}
Loading

0 comments on commit 79f71ba

Please sign in to comment.