From bb8959160ae434202eb33f9d9ca1640d916b07cc Mon Sep 17 00:00:00 2001 From: glax Date: Mon, 12 Feb 2024 02:01:31 +0100 Subject: [PATCH] Mark exposed fields and methods --- CShocker/Devices/APIs/PiShockHttp.cs | 4 ++-- CShocker/Devices/APIs/PiShockSerial.cs | 4 ++-- CShocker/Devices/Abstract/Api.cs | 2 +- CShocker/Devices/Abstract/OpenShockApi.cs | 7 +++++-- CShocker/Devices/Abstract/SerialPortInfo.cs | 3 ++- CShocker/Ranges/IntegerRange.cs | 1 + CShocker/Shockers/Abstract/Shocker.cs | 1 + CShocker/Shockers/Additional/ShockerJsonConverter.cs | 3 +-- CShocker/Shockers/OpenShockShocker.cs | 11 +++++++---- CShocker/Shockers/PiShockShocker.cs | 2 +- 10 files changed, 23 insertions(+), 15 deletions(-) diff --git a/CShocker/Devices/APIs/PiShockHttp.cs b/CShocker/Devices/APIs/PiShockHttp.cs index 958c76d..2b04111 100644 --- a/CShocker/Devices/APIs/PiShockHttp.cs +++ b/CShocker/Devices/APIs/PiShockHttp.cs @@ -8,8 +8,8 @@ namespace CShocker.Devices.APIs; public class PiShockHttp : PiShockApi { - // ReSharper disable twice MemberCanBePrivate.Global external usage - public string Username, Endpoint, ApiKey; + // ReSharper disable thrice MemberCanBePrivate.Global -> Exposed + public readonly string Username, Endpoint, ApiKey; public PiShockHttp(string apiKey, string username, string endpoint = "https://do.pishock.com/api/apioperate", ILogger? logger = null) : base(DeviceApi.PiShockHttp, logger) { diff --git a/CShocker/Devices/APIs/PiShockSerial.cs b/CShocker/Devices/APIs/PiShockSerial.cs index e8a1c4d..ed4797d 100644 --- a/CShocker/Devices/APIs/PiShockSerial.cs +++ b/CShocker/Devices/APIs/PiShockSerial.cs @@ -1,7 +1,6 @@ using System.IO.Ports; using CShocker.Devices.Abstract; using CShocker.Devices.Additional; -using CShocker.Ranges; using CShocker.Shockers.Abstract; using Microsoft.Extensions.Logging; @@ -10,7 +9,8 @@ namespace CShocker.Devices.APIs; public class PiShockSerial : PiShockApi { private const int BaudRate = 115200; - public SerialPortInfo SerialPortI; + // ReSharper disable once MemberCanBePrivate.Global -> Exposed + public readonly SerialPortInfo SerialPortI; private readonly SerialPort _serialPort; public PiShockSerial(DeviceApi apiType, SerialPortInfo serialPortI, ILogger? logger = null) : base(apiType, logger) diff --git a/CShocker/Devices/Abstract/Api.cs b/CShocker/Devices/Abstract/Api.cs index 0f9674d..2dd54c5 100644 --- a/CShocker/Devices/Abstract/Api.cs +++ b/CShocker/Devices/Abstract/Api.cs @@ -7,7 +7,7 @@ namespace CShocker.Devices.Abstract; public abstract class Api : IDisposable { - // ReSharper disable 4 times MemberCanBePrivate.Global external use + // ReSharper disable 4 times MemberCanBePrivate.Global -> Exposed protected ILogger? Logger; public readonly DeviceApi ApiType; private readonly Queue> _queue = new(); diff --git a/CShocker/Devices/Abstract/OpenShockApi.cs b/CShocker/Devices/Abstract/OpenShockApi.cs index 6ee6a32..5db4cfc 100644 --- a/CShocker/Devices/Abstract/OpenShockApi.cs +++ b/CShocker/Devices/Abstract/OpenShockApi.cs @@ -8,10 +8,12 @@ namespace CShocker.Devices.Abstract; public abstract class OpenShockApi : Api { + // ReSharper disable twice MemberCanBeProtected.Global -> Exposed public string Endpoint { get; init; } public string ApiKey { get; init; } private const string DefaultEndpoint = "https://api.shocklink.net"; + // ReSharper disable once PublicConstructorInAbstractClass -> Exposed public OpenShockApi(DeviceApi apiType, string apiKey, string endpoint = DefaultEndpoint, ILogger? logger = null) : base(apiType, new IntegerRange(0, 100), new IntegerRange(300, 30000), logger) { this.Endpoint = endpoint; @@ -33,12 +35,13 @@ public abstract class OpenShockApi : Api return HashCode.Combine(Endpoint, ApiKey); } - public List GetShockers() + public IEnumerable GetShockers() { return GetShockers(this.ApiKey, this, this.Endpoint, this.Logger); } - public static List GetShockers(string apiKey, OpenShockApi api, string apiEndpoint = DefaultEndpoint, ILogger? logger = null) + // ReSharper disable once MemberCanBePrivate.Global + public static IEnumerable GetShockers(string apiKey, OpenShockApi api, string apiEndpoint = DefaultEndpoint, ILogger? logger = null) { List shockers = new(); diff --git a/CShocker/Devices/Abstract/SerialPortInfo.cs b/CShocker/Devices/Abstract/SerialPortInfo.cs index 1ce7871..1ef3373 100644 --- a/CShocker/Devices/Abstract/SerialPortInfo.cs +++ b/CShocker/Devices/Abstract/SerialPortInfo.cs @@ -1,7 +1,8 @@ namespace CShocker.Devices.Abstract; -public struct SerialPortInfo +public readonly struct SerialPortInfo { + // ReSharper disable thrice MemberCanBePrivate.Global -> Exposed public readonly string? PortName, Description, Manufacturer, DeviceID; public SerialPortInfo(string? portName, string? description, string? manufacturer, string? deviceID) diff --git a/CShocker/Ranges/IntegerRange.cs b/CShocker/Ranges/IntegerRange.cs index 0cb143c..dea1aa2 100644 --- a/CShocker/Ranges/IntegerRange.cs +++ b/CShocker/Ranges/IntegerRange.cs @@ -2,6 +2,7 @@ public readonly struct IntegerRange { + // ReSharper disable twice MemberCanBePrivate.Global -> Exposed public readonly int Min, Max; public IntegerRange(int min, int max) diff --git a/CShocker/Shockers/Abstract/Shocker.cs b/CShocker/Shockers/Abstract/Shocker.cs index 0c776f3..3ac77f0 100644 --- a/CShocker/Shockers/Abstract/Shocker.cs +++ b/CShocker/Shockers/Abstract/Shocker.cs @@ -5,6 +5,7 @@ namespace CShocker.Shockers.Abstract; public abstract class Shocker : IDisposable { + // ReSharper disable once MemberCanBePrivate.Global -> Exposed public Api Api { get; } internal Shocker(Api api) diff --git a/CShocker/Shockers/Additional/ShockerJsonConverter.cs b/CShocker/Shockers/Additional/ShockerJsonConverter.cs index 013ec1d..ef03d15 100644 --- a/CShocker/Shockers/Additional/ShockerJsonConverter.cs +++ b/CShocker/Shockers/Additional/ShockerJsonConverter.cs @@ -22,7 +22,6 @@ public class ShockerJsonConverter : JsonConverter { return jo.ToObject(serializer)!; } - throw new Exception(); } public override bool CanWrite => false; @@ -32,6 +31,6 @@ public class ShockerJsonConverter : JsonConverter /// public override void WriteJson(JsonWriter writer, object? value, JsonSerializer serializer) { - throw new Exception("Dont call this"); + throw new NotImplementedException("Dont call this"); } } \ No newline at end of file diff --git a/CShocker/Shockers/OpenShockShocker.cs b/CShocker/Shockers/OpenShockShocker.cs index 477042f..4fc831c 100644 --- a/CShocker/Shockers/OpenShockShocker.cs +++ b/CShocker/Shockers/OpenShockShocker.cs @@ -1,13 +1,16 @@ -using System.Diagnostics.CodeAnalysis; -using CShocker.Devices.Abstract; +using CShocker.Devices.Abstract; using CShocker.Shockers.Abstract; namespace CShocker.Shockers; -#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. -[SuppressMessage("ReSharper", "InconsistentNaming")] public class OpenShockShocker : Shocker { + // ReSharper disable thrice MemberCanBePrivate.Global -> Exposed + public readonly string Name, ID; + public readonly short RfId; + public readonly OpenShockModel Model; + public readonly DateTime CreatedOn; + public readonly bool IsPaused; public string name, id; public short rfId; public OpenShockModel model; diff --git a/CShocker/Shockers/PiShockShocker.cs b/CShocker/Shockers/PiShockShocker.cs index bdc660d..3774723 100644 --- a/CShocker/Shockers/PiShockShocker.cs +++ b/CShocker/Shockers/PiShockShocker.cs @@ -5,7 +5,7 @@ namespace CShocker.Shockers; public class PiShockShocker : Shocker { - public string Code; + public readonly string Code; public override bool Equals(object? obj) {