diff --git a/FileDbCache/UWP/FileDbCache.UWP.cs b/FileDbCache/UWP/FileDbCache.UWP.cs index d1734265..8d7bec18 100644 --- a/FileDbCache/UWP/FileDbCache.UWP.cs +++ b/FileDbCache/UWP/FileDbCache.UWP.cs @@ -17,12 +17,12 @@ namespace MapControl.Caching { if (folder == null) { - throw new ArgumentNullException("The parameter folder must not be null."); + throw new ArgumentNullException(nameof(folder)); } if (string.IsNullOrEmpty(fileName)) { - throw new ArgumentException("The parameter fileName must not be null or empty."); + throw new ArgumentException("The fileName argument must not be null or empty", nameof(fileName)); } Open(Path.Combine(folder.Path, fileName)); diff --git a/FileDbCache/WPF/FileDbCache.WPF.cs b/FileDbCache/WPF/FileDbCache.WPF.cs index a0aa8269..3faa2d23 100644 --- a/FileDbCache/WPF/FileDbCache.WPF.cs +++ b/FileDbCache/WPF/FileDbCache.WPF.cs @@ -17,7 +17,7 @@ namespace MapControl.Caching { if (string.IsNullOrEmpty(path)) { - throw new ArgumentException("The parameter path must not be null or empty."); + throw new ArgumentException("The path argument must not be null or empty.", nameof(path)); } if (string.IsNullOrEmpty(Path.GetExtension(path))) @@ -82,12 +82,12 @@ namespace MapControl.Caching if (key == null) { - throw new ArgumentNullException("The parameter key must not be null."); + throw new ArgumentNullException(nameof(key)); } try { - return fileDb.GetRecordByKey(key, new string[0], false) != null; + return fileDb.GetRecordByKey(key, Array.Empty(), false) != null; } catch (Exception ex) { @@ -106,7 +106,7 @@ namespace MapControl.Caching if (key == null) { - throw new ArgumentNullException("The parameter key must not be null."); + throw new ArgumentNullException(nameof(key)); } var record = GetRecordByKey(key); @@ -144,12 +144,12 @@ namespace MapControl.Caching if (key == null) { - throw new ArgumentNullException("The parameter key must not be null."); + throw new ArgumentNullException(nameof(key)); } if (!(value is ImageCacheItem imageCacheItem)) { - throw new ArgumentException("The parameter value must be a MapControl.Caching.ImageCacheItem instance."); + throw new ArgumentException("The value argument must be a MapControl.Caching.ImageCacheItem instance.", nameof(value)); } AddOrUpdateRecord(key, imageCacheItem.Buffer, imageCacheItem.Expiration); diff --git a/MapControl/Shared/LocationCollection.cs b/MapControl/Shared/LocationCollection.cs index 52733042..937ac6cf 100644 --- a/MapControl/Shared/LocationCollection.cs +++ b/MapControl/Shared/LocationCollection.cs @@ -9,7 +9,8 @@ using System.Linq; namespace MapControl { /// - /// A collection of Locations with support for string parsing and calculation of great circle and rhumb line locations. + /// A collection of Locations with support for string parsing + /// and calculation of great circle and rhumb line locations. /// #if !WINDOWS_UWP [System.ComponentModel.TypeConverter(typeof(LocationCollectionConverter))] @@ -64,7 +65,7 @@ namespace MapControl if (resolution <= 0d) { throw new ArgumentOutOfRangeException( - nameof(resolution), "The parameter resolution must be greater than zero."); + nameof(resolution), "The resolution argument must be greater than zero."); } resolution *= Math.PI / 180d; @@ -126,7 +127,7 @@ namespace MapControl if (resolution <= 0d) { throw new ArgumentOutOfRangeException( - nameof(resolution), "The parameter resolution must be greater than zero."); + nameof(resolution), "The resolution argument must be greater than zero."); } resolution *= Math.PI / 180d; @@ -139,13 +140,13 @@ namespace MapControl if (double.IsInfinity(y1)) { throw new ArgumentOutOfRangeException( - nameof(location1), "The parameter location1 must have an absolute latitude value of less than 90 degrees."); + nameof(location1), "The location1 argument must have an absolute latitude value of less than 90."); } if (double.IsInfinity(y2)) { throw new ArgumentOutOfRangeException( - nameof(location2), "The parameter location2 must have an absolute latitude value of less than 90 degrees."); + nameof(location2), "The location2 argument must have an absolute latitude value of less than 90."); } var lon1 = location1.Longitude; @@ -154,12 +155,12 @@ namespace MapControl var dlon = lon2 - lon1; var dy = y2 - y1; - // sec(beta) = 1 / cos(atan(dx,dy)) = sqrt(1 + (dx/dy)^2) + // sec(beta) = 1 / cos(atan(dlon,dy)) = sqrt(1 + (dlon/dy)^2) var sec = Math.Sqrt(1d + dlon * dlon / (dy * dy)); var s12 = sec < 1000d ? Math.Abs(dlat * Math.PI / 180d * sec) - : Math.Abs(dlon * Math.PI / 180d); + : Math.Abs(dlon * Math.PI / 180d * Math.Cos((lat1 + lat2) * Math.PI / 360d)); var locations = new LocationCollection(new Location(lat1, lon1)); diff --git a/MapControl/Shared/WmtsTileMatrixSet.cs b/MapControl/Shared/WmtsTileMatrixSet.cs index 795243b6..9a9fd8fc 100644 --- a/MapControl/Shared/WmtsTileMatrixSet.cs +++ b/MapControl/Shared/WmtsTileMatrixSet.cs @@ -18,17 +18,17 @@ namespace MapControl { if (string.IsNullOrEmpty(identifier)) { - throw new ArgumentException("The parameter identifier must not be null or empty."); + throw new ArgumentException("The identifier argument must not be null or empty.", nameof(identifier)); } if (string.IsNullOrEmpty(supportedCrs)) { - throw new ArgumentException("The parameter supportedCrs must not be null or empty."); + throw new ArgumentException("The supportedCrs argument must not be null or empty.", nameof(supportedCrs)); } - if (tileMatrixes == null || tileMatrixes.Count() <= 0) + if (tileMatrixes == null || !tileMatrixes.Any()) { - throw new ArgumentException("The parameter tileMatrixes must not be null or an empty collection."); + throw new ArgumentException("The tileMatrixes argument must not be null or an empty collection.", nameof(tileMatrixes)); } Identifier = identifier; diff --git a/MapControl/UWP/ImageFileCache.UWP.cs b/MapControl/UWP/ImageFileCache.UWP.cs index deacb094..5a31d7d6 100644 --- a/MapControl/UWP/ImageFileCache.UWP.cs +++ b/MapControl/UWP/ImageFileCache.UWP.cs @@ -17,7 +17,7 @@ namespace MapControl.Caching public ImageFileCache(StorageFolder folder) { - this.folder = folder ?? throw new ArgumentNullException("The parameter rootFolder must not be null."); + this.folder = folder ?? throw new ArgumentNullException(nameof(folder)); Debug.WriteLine("Created ImageFileCache in " + folder.Path); } diff --git a/MapControl/WPF/ImageFileCache.WPF.cs b/MapControl/WPF/ImageFileCache.WPF.cs index 56ec8f63..0e483a6a 100644 --- a/MapControl/WPF/ImageFileCache.WPF.cs +++ b/MapControl/WPF/ImageFileCache.WPF.cs @@ -34,7 +34,7 @@ namespace MapControl.Caching { if (string.IsNullOrEmpty(directory)) { - throw new ArgumentException("The parameter directory must not be null or empty."); + throw new ArgumentException("The directory argument must not be null or empty.", nameof(directory)); } rootDirectory = directory; @@ -85,7 +85,7 @@ namespace MapControl.Caching if (key == null) { - throw new ArgumentNullException("The parameter key must not be null."); + throw new ArgumentNullException(nameof(key)); } return memoryCache.Contains(key) || FindFile(key) != null; @@ -100,7 +100,7 @@ namespace MapControl.Caching if (key == null) { - throw new ArgumentNullException("The parameter key must not be null."); + throw new ArgumentNullException(nameof(key)); } var imageCacheItem = memoryCache.Get(key) as ImageCacheItem; @@ -157,12 +157,12 @@ namespace MapControl.Caching if (key == null) { - throw new ArgumentNullException("The parameter key must not be null."); + throw new ArgumentNullException(nameof(key)); } if (!(value is ImageCacheItem imageCacheItem)) { - throw new ArgumentException("The parameter value must be a MapControl.Caching.ImageCacheItem instance."); + throw new ArgumentException("The value argument must be a MapControl.Caching.ImageCacheItem instance.", nameof(value)); } memoryCache.Set(key, imageCacheItem, policy); @@ -239,7 +239,7 @@ namespace MapControl.Caching if (key == null) { - throw new ArgumentNullException("The parameter key must not be null."); + throw new ArgumentNullException(nameof(key)); } memoryCache.Remove(key); diff --git a/MapProjections/Shared/GeoApiProjection.cs b/MapProjections/Shared/GeoApiProjection.cs index a48295fd..1ae0b627 100644 --- a/MapProjections/Shared/GeoApiProjection.cs +++ b/MapProjections/Shared/GeoApiProjection.cs @@ -39,7 +39,7 @@ namespace MapControl.Projections get { return coordinateSystem; } set { - coordinateSystem = value ?? throw new ArgumentNullException("The property value must not be null."); + coordinateSystem = value ?? throw new ArgumentNullException(nameof(value)); var transformFactory = new CoordinateTransformationFactory(); diff --git a/MapProjections/Shared/UtmProjection.cs b/MapProjections/Shared/UtmProjection.cs index a7a8db7c..9b00b912 100644 --- a/MapProjections/Shared/UtmProjection.cs +++ b/MapProjections/Shared/UtmProjection.cs @@ -40,7 +40,7 @@ namespace MapControl.Projections { if (zoneNumber < 1 || zoneNumber > 61) { - throw new ArgumentException("Invalid UTM zone number."); + throw new ArgumentException("Invalid UTM zone number.", nameof(zoneNumber)); } var zoneName = zoneNumber.ToString() + (north ? "N" : "S"); diff --git a/SQLiteCache/UWP/SQLiteCache.UWP.cs b/SQLiteCache/UWP/SQLiteCache.UWP.cs index 766a5acd..a79b2ad9 100644 --- a/SQLiteCache/UWP/SQLiteCache.UWP.cs +++ b/SQLiteCache/UWP/SQLiteCache.UWP.cs @@ -21,12 +21,12 @@ namespace MapControl.Caching { if (folder == null) { - throw new ArgumentNullException("The parameter folder must not be null."); + throw new ArgumentNullException(nameof(folder)); } if (string.IsNullOrEmpty(fileName)) { - throw new ArgumentException("The parameter fileName must not be null or empty."); + throw new ArgumentException("The fileName argument must not be null or empty.", nameof(fileName)); } connection = Open(Path.Combine(folder.Path, fileName)); diff --git a/SQLiteCache/WPF/SQLiteCache.WPF.cs b/SQLiteCache/WPF/SQLiteCache.WPF.cs index 3fda2133..73a1105d 100644 --- a/SQLiteCache/WPF/SQLiteCache.WPF.cs +++ b/SQLiteCache/WPF/SQLiteCache.WPF.cs @@ -21,7 +21,7 @@ namespace MapControl.Caching { if (string.IsNullOrEmpty(path)) { - throw new ArgumentException("The parameter path must not be null or empty."); + throw new ArgumentException("The path argument must not be null or empty.", nameof(path)); } if (string.IsNullOrEmpty(Path.GetExtension(path))) @@ -91,7 +91,7 @@ namespace MapControl.Caching if (key == null) { - throw new ArgumentNullException("The parameter key must not be null."); + throw new ArgumentNullException(nameof(key)); } try @@ -118,7 +118,7 @@ namespace MapControl.Caching if (key == null) { - throw new ArgumentNullException("The parameter key must not be null."); + throw new ArgumentNullException(nameof(key)); } try @@ -166,12 +166,12 @@ namespace MapControl.Caching if (key == null) { - throw new ArgumentNullException("The parameter key must not be null."); + throw new ArgumentNullException(nameof(key)); } if (!(value is ImageCacheItem imageCacheItem)) { - throw new ArgumentException("The parameter value must be a MapControl.Caching.ImageCacheItem instance."); + throw new ArgumentException("The value argument must be a MapControl.Caching.ImageCacheItem instance.", nameof(value)); } try