From d6f72c8222a8d99d32643cbbf97786b9cbd9e9fe Mon Sep 17 00:00:00 2001 From: Colin Date: Fri, 19 Jul 2019 13:22:15 +0100 Subject: [PATCH] Code inspections --- AstroMath.UnitTests/AstroMathsUnitTests.cs | 4 +-- .../AstroMaths/AltitudeData.cs | 2 +- Meade.net.Telescope/Rates.cs | 36 +++++++------------ Meade.net.Telescope/Telescope.cs | 21 +++++------ Meade.net.focuser/Focuser.cs | 9 +---- Meade.net/ClassFactory.cs | 16 ++++----- Meade.net/SharedResources.cs | 2 +- 7 files changed, 36 insertions(+), 54 deletions(-) diff --git a/AstroMath.UnitTests/AstroMathsUnitTests.cs b/AstroMath.UnitTests/AstroMathsUnitTests.cs index b54ab61..a72f498 100644 --- a/AstroMath.UnitTests/AstroMathsUnitTests.cs +++ b/AstroMath.UnitTests/AstroMathsUnitTests.cs @@ -58,7 +58,7 @@ namespace AstroMath.UnitTests } [Test] - public void UTtoGST() + public void UTtoGst() { DateTime dateTime = new DateTime(2019, 05, 18, 22, 26, 15, DateTimeKind.Utc); double gst = _astroMath.UTtoGST(dateTime); @@ -76,7 +76,7 @@ namespace AstroMath.UnitTests } [Test] - public void GSTtoLST() + public void GsTtoLst() { double gst = 14.257589512545053; var longitude = -1.7833333333333332; diff --git a/Meade.net.Telescope/AstroMaths/AltitudeData.cs b/Meade.net.Telescope/AstroMaths/AltitudeData.cs index a00f7db..6ca2890 100644 --- a/Meade.net.Telescope/AstroMaths/AltitudeData.cs +++ b/Meade.net.Telescope/AstroMaths/AltitudeData.cs @@ -7,6 +7,6 @@ namespace ASCOM.Meade.net.AstroMaths public DateTime UtcDateTime { get; set; } public double SiteLatitude { get; set; } public double SiteLongitude { get; set; } - public EquatorialCoordinates equatorialCoordinates { get; set; } + public EquatorialCoordinates EquatorialCoordinates { get; set; } } } \ No newline at end of file diff --git a/Meade.net.Telescope/Rates.cs b/Meade.net.Telescope/Rates.cs index 550f28a..bf75539 100644 --- a/Meade.net.Telescope/Rates.cs +++ b/Meade.net.Telescope/Rates.cs @@ -19,8 +19,8 @@ namespace ASCOM.Meade.net [ComVisible(true)] public class Rate : IRate { - private double maximum = 0; - private double minimum = 0; + private double _maximum = 0; + private double _minimum = 0; // // Default constructor - Internal prevents public creation @@ -28,8 +28,8 @@ namespace ASCOM.Meade.net // internal Rate(double minimum, double maximum) { - this.maximum = maximum; - this.minimum = minimum; + _maximum = maximum; + _minimum = minimum; } #region Implementation of IRate @@ -41,14 +41,14 @@ namespace ASCOM.Meade.net public double Maximum { - get { return maximum; } - set { maximum = value; } + get => _maximum; + set => _maximum = value; } public double Minimum { - get { return minimum; } - set { minimum = value; } + get => _minimum; + set => _minimum = value; } #endregion @@ -112,10 +112,7 @@ namespace ASCOM.Meade.net #region IAxisRates Members - public int Count - { - get { return rates.Length; } - } + public int Count => rates.Length; public void Dispose() { @@ -127,10 +124,7 @@ namespace ASCOM.Meade.net return rates.GetEnumerator(); } - public IRate this[int index] - { - get { return rates[index - 1]; } // 1-based - } + public IRate this[int index] => rates[index - 1]; #endregion } @@ -178,10 +172,7 @@ namespace ASCOM.Meade.net #region ITrackingRates Members - public int Count - { - get { return trackingRates.Length; } - } + public int Count => trackingRates.Length; public IEnumerator GetEnumerator() { @@ -194,10 +185,7 @@ namespace ASCOM.Meade.net // TODO Add any required object cleanup here } - public DriveRates this[int index] - { - get { return trackingRates[index - 1]; } // 1-based - } + public DriveRates this[int index] => trackingRates[index - 1]; #endregion diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index d57d84a..c082f33 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -6,6 +6,7 @@ using ASCOM.Astrometry.AstroUtils; using ASCOM.Utilities; using ASCOM.DeviceInterface; using System.Collections; +using System.Globalization; using System.Reflection; using ASCOM.Meade.net.AstroMaths; using ASCOM.Meade.net.Wrapper; @@ -38,15 +39,15 @@ namespace ASCOM.Meade.net /// The DeviceID is used by ASCOM applications to load the driver at runtime. /// //internal static string driverID = "ASCOM.Meade.net.Telescope"; - 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 @@ -583,7 +584,7 @@ namespace ASCOM.Meade.net UtcDateTime = UTCDate, SiteLongitude = SiteLongitude, SiteLatitude = SiteLatitude, - equatorialCoordinates = new EquatorialCoordinates() + EquatorialCoordinates = new EquatorialCoordinates() { RightAscension = RightAscension, Declination = Declination @@ -591,8 +592,8 @@ namespace ASCOM.Meade.net }); double hourAngle = _astroMaths.RightAscensionToHourAngle(altitudeData.UtcDateTime, altitudeData.SiteLongitude, - altitudeData.equatorialCoordinates.RightAscension); - var altAz = _astroMaths.ConvertEqToHoz(hourAngle, altitudeData.SiteLatitude, altitudeData.equatorialCoordinates); + altitudeData.EquatorialCoordinates.RightAscension); + var altAz = _astroMaths.ConvertEqToHoz(hourAngle, altitudeData.SiteLatitude, altitudeData.EquatorialCoordinates); return altAz; } @@ -632,7 +633,7 @@ namespace ASCOM.Meade.net LogMessage("AtPark", "Get - " + _atPark); return _atPark; } - private set { _atPark = value; } + private set => _atPark = value; } public IAxisRates AxisRates(TelescopeAxes Axis) @@ -842,7 +843,7 @@ namespace ASCOM.Meade.net get { double declination = 0.0; - LogMessage("DeclinationRate", "Get - " + declination.ToString()); + LogMessage("DeclinationRate", "Get - " + declination.ToString(CultureInfo.InvariantCulture)); return declination; } set @@ -1141,7 +1142,7 @@ namespace ASCOM.Meade.net get { double rightAscensionRate = 0.0; - LogMessage("RightAscensionRate", "Get - " + rightAscensionRate.ToString()); + LogMessage("RightAscensionRate", "Get - " + rightAscensionRate.ToString(CultureInfo.InvariantCulture)); return rightAscensionRate; } set @@ -1192,7 +1193,7 @@ namespace ASCOM.Meade.net // Reduce to the range 0 to 24 hours siderealTime = _astroUtilities.ConditionRA(siderealTime); - LogMessage("SiderealTime", "Get - " + siderealTime.ToString()); + LogMessage("SiderealTime", "Get - " + siderealTime.ToString(CultureInfo.InvariantCulture)); return siderealTime; } } diff --git a/Meade.net.focuser/Focuser.cs b/Meade.net.focuser/Focuser.cs index d39d12c..de1c03b 100644 --- a/Meade.net.focuser/Focuser.cs +++ b/Meade.net.focuser/Focuser.cs @@ -430,14 +430,7 @@ namespace ASCOM.Meade.net }); } - public int Position - { - get - { - throw new PropertyNotImplementedException("Position", false); - //return focuserPosition; // Return the focuser position - } - } + public int Position => throw new PropertyNotImplementedException("Position", false); public double StepSize { diff --git a/Meade.net/ClassFactory.cs b/Meade.net/ClassFactory.cs index 1626f5c..7b61d4f 100644 --- a/Meade.net/ClassFactory.cs +++ b/Meade.net/ClassFactory.cs @@ -109,9 +109,9 @@ namespace ASCOM.Meade.net #region Constructor and Private ClassFactory Data - protected Type m_ClassType; + protected readonly Type m_ClassType; protected Guid m_ClassId; - protected ArrayList m_InterfaceTypes; + protected readonly ArrayList m_InterfaceTypes; protected uint m_ClassContext; protected uint m_Flags; protected UInt32 m_locked = 0; @@ -140,20 +140,20 @@ namespace ASCOM.Meade.net #region Common ClassFactory Methods public uint ClassContext { - get { return m_ClassContext; } - set { m_ClassContext = value; } + get => m_ClassContext; + set => m_ClassContext = value; } public Guid ClassId { - get { return m_ClassId; } - set { m_ClassId = value; } + get => m_ClassId; + set => m_ClassId = value; } public uint Flags { - get { return m_Flags; } - set { m_Flags = value; } + get => m_Flags; + set => m_Flags = value; } public bool RegisterClassObject() diff --git a/Meade.net/SharedResources.cs b/Meade.net/SharedResources.cs index b3b15f7..1d5a709 100644 --- a/Meade.net/SharedResources.cs +++ b/Meade.net/SharedResources.cs @@ -146,7 +146,7 @@ namespace ASCOM.Meade.net } } } - get { return SharedSerial.Connected; } + get => SharedSerial.Connected; } #endregion