Fixed ArgumentExceptions

This commit is contained in:
ClemensF 2021-02-11 23:34:37 +01:00
parent 87ff5043f6
commit d4f5456dd5
10 changed files with 36 additions and 35 deletions

View file

@ -17,12 +17,12 @@ namespace MapControl.Caching
{ {
if (folder == null) if (folder == null)
{ {
throw new ArgumentNullException("The parameter folder must not be null."); throw new ArgumentNullException(nameof(folder));
} }
if (string.IsNullOrEmpty(fileName)) 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)); Open(Path.Combine(folder.Path, fileName));

View file

@ -17,7 +17,7 @@ namespace MapControl.Caching
{ {
if (string.IsNullOrEmpty(path)) 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))) if (string.IsNullOrEmpty(Path.GetExtension(path)))
@ -82,12 +82,12 @@ namespace MapControl.Caching
if (key == null) if (key == null)
{ {
throw new ArgumentNullException("The parameter key must not be null."); throw new ArgumentNullException(nameof(key));
} }
try try
{ {
return fileDb.GetRecordByKey(key, new string[0], false) != null; return fileDb.GetRecordByKey(key, Array.Empty<string>(), false) != null;
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -106,7 +106,7 @@ namespace MapControl.Caching
if (key == null) if (key == null)
{ {
throw new ArgumentNullException("The parameter key must not be null."); throw new ArgumentNullException(nameof(key));
} }
var record = GetRecordByKey(key); var record = GetRecordByKey(key);
@ -144,12 +144,12 @@ namespace MapControl.Caching
if (key == null) if (key == null)
{ {
throw new ArgumentNullException("The parameter key must not be null."); throw new ArgumentNullException(nameof(key));
} }
if (!(value is ImageCacheItem imageCacheItem)) 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); AddOrUpdateRecord(key, imageCacheItem.Buffer, imageCacheItem.Expiration);

View file

@ -9,7 +9,8 @@ using System.Linq;
namespace MapControl namespace MapControl
{ {
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
#if !WINDOWS_UWP #if !WINDOWS_UWP
[System.ComponentModel.TypeConverter(typeof(LocationCollectionConverter))] [System.ComponentModel.TypeConverter(typeof(LocationCollectionConverter))]
@ -64,7 +65,7 @@ namespace MapControl
if (resolution <= 0d) if (resolution <= 0d)
{ {
throw new ArgumentOutOfRangeException( 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; resolution *= Math.PI / 180d;
@ -126,7 +127,7 @@ namespace MapControl
if (resolution <= 0d) if (resolution <= 0d)
{ {
throw new ArgumentOutOfRangeException( 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; resolution *= Math.PI / 180d;
@ -139,13 +140,13 @@ namespace MapControl
if (double.IsInfinity(y1)) if (double.IsInfinity(y1))
{ {
throw new ArgumentOutOfRangeException( 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)) if (double.IsInfinity(y2))
{ {
throw new ArgumentOutOfRangeException( 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; var lon1 = location1.Longitude;
@ -154,12 +155,12 @@ namespace MapControl
var dlon = lon2 - lon1; var dlon = lon2 - lon1;
var dy = y2 - y1; 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 sec = Math.Sqrt(1d + dlon * dlon / (dy * dy));
var s12 = sec < 1000d var s12 = sec < 1000d
? Math.Abs(dlat * Math.PI / 180d * sec) ? 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)); var locations = new LocationCollection(new Location(lat1, lon1));

View file

@ -18,17 +18,17 @@ namespace MapControl
{ {
if (string.IsNullOrEmpty(identifier)) 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)) 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; Identifier = identifier;

View file

@ -17,7 +17,7 @@ namespace MapControl.Caching
public ImageFileCache(StorageFolder folder) 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); Debug.WriteLine("Created ImageFileCache in " + folder.Path);
} }

View file

@ -34,7 +34,7 @@ namespace MapControl.Caching
{ {
if (string.IsNullOrEmpty(directory)) 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; rootDirectory = directory;
@ -85,7 +85,7 @@ namespace MapControl.Caching
if (key == null) 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; return memoryCache.Contains(key) || FindFile(key) != null;
@ -100,7 +100,7 @@ namespace MapControl.Caching
if (key == null) 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; var imageCacheItem = memoryCache.Get(key) as ImageCacheItem;
@ -157,12 +157,12 @@ namespace MapControl.Caching
if (key == null) if (key == null)
{ {
throw new ArgumentNullException("The parameter key must not be null."); throw new ArgumentNullException(nameof(key));
} }
if (!(value is ImageCacheItem imageCacheItem)) 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); memoryCache.Set(key, imageCacheItem, policy);
@ -239,7 +239,7 @@ namespace MapControl.Caching
if (key == null) if (key == null)
{ {
throw new ArgumentNullException("The parameter key must not be null."); throw new ArgumentNullException(nameof(key));
} }
memoryCache.Remove(key); memoryCache.Remove(key);

View file

@ -39,7 +39,7 @@ namespace MapControl.Projections
get { return coordinateSystem; } get { return coordinateSystem; }
set set
{ {
coordinateSystem = value ?? throw new ArgumentNullException("The property value must not be null."); coordinateSystem = value ?? throw new ArgumentNullException(nameof(value));
var transformFactory = new CoordinateTransformationFactory(); var transformFactory = new CoordinateTransformationFactory();

View file

@ -40,7 +40,7 @@ namespace MapControl.Projections
{ {
if (zoneNumber < 1 || zoneNumber > 61) 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"); var zoneName = zoneNumber.ToString() + (north ? "N" : "S");

View file

@ -21,12 +21,12 @@ namespace MapControl.Caching
{ {
if (folder == null) if (folder == null)
{ {
throw new ArgumentNullException("The parameter folder must not be null."); throw new ArgumentNullException(nameof(folder));
} }
if (string.IsNullOrEmpty(fileName)) 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)); connection = Open(Path.Combine(folder.Path, fileName));

View file

@ -21,7 +21,7 @@ namespace MapControl.Caching
{ {
if (string.IsNullOrEmpty(path)) 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))) if (string.IsNullOrEmpty(Path.GetExtension(path)))
@ -91,7 +91,7 @@ namespace MapControl.Caching
if (key == null) if (key == null)
{ {
throw new ArgumentNullException("The parameter key must not be null."); throw new ArgumentNullException(nameof(key));
} }
try try
@ -118,7 +118,7 @@ namespace MapControl.Caching
if (key == null) if (key == null)
{ {
throw new ArgumentNullException("The parameter key must not be null."); throw new ArgumentNullException(nameof(key));
} }
try try
@ -166,12 +166,12 @@ namespace MapControl.Caching
if (key == null) if (key == null)
{ {
throw new ArgumentNullException("The parameter key must not be null."); throw new ArgumentNullException(nameof(key));
} }
if (!(value is ImageCacheItem imageCacheItem)) 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 try