From 0e98f0e3709a92b999586ba3896433a399a54110 Mon Sep 17 00:00:00 2001 From: Colin Date: Fri, 19 Jul 2019 14:33:41 +0100 Subject: [PATCH] Code inspections --- Meade.net.Telescope/Rates.cs | 2 +- Meade.net.focuser/Focuser.cs | 20 +++++----- Meade.net/ClassFactory.cs | 70 +++++++++++++++------------------- Meade.net/GarbageCollection.cs | 28 +++++++------- Meade.net/SharedResources.cs | 10 ++--- 5 files changed, 60 insertions(+), 70 deletions(-) diff --git a/Meade.net.Telescope/Rates.cs b/Meade.net.Telescope/Rates.cs index 8d9e970..b3f6f22 100644 --- a/Meade.net.Telescope/Rates.cs +++ b/Meade.net.Telescope/Rates.cs @@ -79,7 +79,7 @@ namespace ASCOM.Meade.net // internal AxisRates(TelescopeAxes axis) { - this._axis = axis; + _axis = axis; // // This collection must hold zero or more Rate objects describing the // rates of motion ranges for the Telescope.MoveAxis() method diff --git a/Meade.net.focuser/Focuser.cs b/Meade.net.focuser/Focuser.cs index f2dc2ab..bf3a891 100644 --- a/Meade.net.focuser/Focuser.cs +++ b/Meade.net.focuser/Focuser.cs @@ -38,14 +38,14 @@ namespace ASCOM.Meade.net /// The DeviceID is used by ASCOM applications to load the driver at runtime. /// //internal static string driverID = "ASCOM.Meade.net.Focuser"; - internal static string DriverId = Marshal.GenerateProgIdForType(MethodBase.GetCurrentMethod().DeclaringType); + private static readonly string DriverId = Marshal.GenerateProgIdForType(MethodBase.GetCurrentMethod().DeclaringType); // TODO Change the descriptive string for your driver then remove this line /// /// Driver description that displays in the ASCOM Chooser. /// - private static string _driverDescription = "Meade Generic"; + private static readonly string DriverDescription = "Meade Generic"; - internal static string ComPort; // Variables to hold the currrent device configuration + private static string _comPort; // Variables to hold the currrent device configuration /// /// Private variable to hold an ASCOM Utilities object @@ -193,12 +193,12 @@ namespace ASCOM.Meade.net } catch (Exception ex) { - LogMessage("Connected Set", "Error connecting to port {0} - {1}", ComPort, ex.Message); + LogMessage("Connected Set", "Error connecting to port {0} - {1}", _comPort, ex.Message); } } else { - LogMessage("Connected Set", "Disconnecting from port {0}", ComPort); + LogMessage("Connected Set", "Disconnecting from port {0}", _comPort); _sharedResourcesWrapper.Disconnect("Serial"); IsConnected = false; } @@ -241,8 +241,8 @@ namespace ASCOM.Meade.net // TODO customise this device description get { - Tl.LogMessage("Description Get", _driverDescription); - return _driverDescription; + Tl.LogMessage("Description Get", DriverDescription); + return DriverDescription; } } @@ -284,7 +284,7 @@ namespace ASCOM.Meade.net get { //string name = "Short driver name - please customise"; - string name = _driverDescription; + string name = DriverDescription; Tl.LogMessage("Name Get", name); return name; } @@ -496,7 +496,7 @@ namespace ASCOM.Meade.net p.DeviceType = "Focuser"; if (bRegister) { - p.Register(DriverId, _driverDescription); + p.Register(DriverId, DriverDescription); } else { @@ -577,7 +577,7 @@ namespace ASCOM.Meade.net { var profileProperties = _sharedResourcesWrapper.ReadProfile(); Tl.Enabled = profileProperties.TraceLogger; - ComPort = profileProperties.ComPort; + _comPort = profileProperties.ComPort; } /// diff --git a/Meade.net/ClassFactory.cs b/Meade.net/ClassFactory.cs index 1f5c265..4b7feca 100644 --- a/Meade.net/ClassFactory.cs +++ b/Meade.net/ClassFactory.cs @@ -33,8 +33,8 @@ namespace ASCOM.Meade.net #region Access to ole32.dll functions for class factories // Define two common GUID objects for public usage. - public static Guid IidIUnknown = new Guid("{00000000-0000-0000-C000-000000000046}"); - public static Guid IidIDispatch = new Guid("{00020400-0000-0000-C000-000000000046}"); + private static Guid _iidIUnknown = new Guid("{00000000-0000-0000-C000-000000000046}"); + private static Guid _iidIDispatch = new Guid("{00020400-0000-0000-C000-000000000046}"); [Flags] enum Clsctx : uint @@ -109,70 +109,60 @@ namespace ASCOM.Meade.net #region Constructor and Private ClassFactory Data - protected readonly Type MClassType; - protected Guid MClassId; - protected readonly ArrayList MInterfaceTypes; - protected uint MClassContext; - protected uint MFlags; - protected UInt32 MLocked = 0; - protected uint MCookie; - protected string MProgid; + private readonly Type _mClassType; + private Guid _mClassId; + private readonly ArrayList _mInterfaceTypes; + private UInt32 _mLocked = 0; + private uint _mCookie; + private readonly string _mProgid; public ClassFactory(Type type) { if (type == null) throw new ArgumentNullException("type"); - MClassType = type; + _mClassType = type; //PWGS Get the ProgID from the MetaData - MProgid = Marshal.GenerateProgIdForType(type); - MClassId = Marshal.GenerateGuidForType(type); // Should be nailed down by [Guid(...)] - MClassContext = (uint)Clsctx.ClsctxLocalServer; // Default - MFlags = (uint)Regcls.RegclsMultipleuse | // Default + _mProgid = Marshal.GenerateProgIdForType(type); + _mClassId = Marshal.GenerateGuidForType(type); // Should be nailed down by [Guid(...)] + ClassContext = (uint)Clsctx.ClsctxLocalServer; // Default + Flags = (uint)Regcls.RegclsMultipleuse | // Default (uint)Regcls.RegclsSuspended; - MInterfaceTypes = new ArrayList(); + _mInterfaceTypes = new ArrayList(); foreach (Type T in type.GetInterfaces()) // Save all of the implemented interfaces - MInterfaceTypes.Add(T); + _mInterfaceTypes.Add(T); } #endregion #region Common ClassFactory Methods - public uint ClassContext - { - get => MClassContext; - set => MClassContext = value; - } + public uint ClassContext { get; set; } public Guid ClassId { - get => MClassId; - set => MClassId = value; + get => _mClassId; + set => _mClassId = value; } - public uint Flags - { - get => MFlags; - set => MFlags = value; - } + public uint Flags { get; set; } public bool RegisterClassObject() { // Register the class factory int i = CoRegisterClassObject ( - ref MClassId, + ref _mClassId, this, - MClassContext, - MFlags, - out MCookie + ClassContext, + Flags, + out _mCookie ); return (i == 0); } public bool RevokeClassObject() { - int i = CoRevokeClassObject(MCookie); + int i = CoRevokeClassObject(_mCookie); return (i == 0); } @@ -201,25 +191,25 @@ namespace ASCOM.Meade.net // // Handle specific requests for implemented interfaces // - foreach (Type iType in MInterfaceTypes) + foreach (Type iType in _mInterfaceTypes) { if (riid == Marshal.GenerateGuidForType(iType)) { - ppvObject = Marshal.GetComInterfaceForObject(Activator.CreateInstance(MClassType), iType); + ppvObject = Marshal.GetComInterfaceForObject(Activator.CreateInstance(_mClassType), iType); return; } } // // Handle requests for IDispatch or IUnknown on the class // - if (riid == IidIDispatch) + if (riid == _iidIDispatch) { - ppvObject = Marshal.GetIDispatchForObject(Activator.CreateInstance(MClassType)); + ppvObject = Marshal.GetIDispatchForObject(Activator.CreateInstance(_mClassType)); return; } - else if (riid == IidIUnknown) + else if (riid == _iidIUnknown) { - ppvObject = Marshal.GetIUnknownForObject(Activator.CreateInstance(MClassType)); + ppvObject = Marshal.GetIUnknownForObject(Activator.CreateInstance(_mClassType)); } else { diff --git a/Meade.net/GarbageCollection.cs b/Meade.net/GarbageCollection.cs index 714af79..f6d5e82 100644 --- a/Meade.net/GarbageCollection.cs +++ b/Meade.net/GarbageCollection.cs @@ -8,17 +8,17 @@ namespace ASCOM.Meade.net /// class GarbageCollection { - protected bool MBContinueThread; - protected bool MGcWatchStopped; - protected int MIInterval; - protected ManualResetEvent MEventThreadEnded; + private bool _mbContinueThread; + private bool _mGcWatchStopped; + private readonly int _miInterval; + private readonly ManualResetEvent _mEventThreadEnded; public GarbageCollection(int iInterval) { - MBContinueThread = true; - MGcWatchStopped = false; - MIInterval = iInterval; - MEventThreadEnded = new ManualResetEvent(false); + _mbContinueThread = true; + _mGcWatchStopped = false; + _miInterval = iInterval; + _mEventThreadEnded = new ManualResetEvent(false); } public void GcWatch() @@ -27,16 +27,16 @@ namespace ASCOM.Meade.net while (ContinueThread()) { GC.Collect(); - Thread.Sleep(MIInterval); + Thread.Sleep(_miInterval); } - MEventThreadEnded.Set(); + _mEventThreadEnded.Set(); } protected bool ContinueThread() { lock (this) { - return MBContinueThread; + return _mbContinueThread; } } @@ -44,14 +44,14 @@ namespace ASCOM.Meade.net { lock (this) { - MBContinueThread = false; + _mbContinueThread = false; } } public void WaitForThreadToStop() { - MEventThreadEnded.WaitOne(); - MEventThreadEnded.Reset(); + _mEventThreadEnded.WaitOne(); + _mEventThreadEnded.Reset(); } } } diff --git a/Meade.net/SharedResources.cs b/Meade.net/SharedResources.cs index d42147e..5598146 100644 --- a/Meade.net/SharedResources.cs +++ b/Meade.net/SharedResources.cs @@ -153,11 +153,11 @@ namespace ASCOM.Meade.net #region Profile - internal static string DriverId = "ASCOM.MeadeGeneric.Telescope"; + private const string DriverId = "ASCOM.MeadeGeneric.Telescope"; // Constants used for Profile persistence - internal static string ComPortProfileName = "COM Port"; - internal static string TraceStateProfileName = "Trace Level"; + private const string ComPortProfileName = "COM Port"; + private const string TraceStateProfileName = "Trace Level"; public static void WriteProfile(ProfileProperties profileProperties) { @@ -172,8 +172,8 @@ namespace ASCOM.Meade.net } } - private static readonly string ComPortDefault = "COM1"; - internal static string TraceStateDefault = "false"; + private const string ComPortDefault = "COM1"; + private const string TraceStateDefault = "false"; public static ProfileProperties ReadProfile() {