diff --git a/FileDbCache/WPF/FileDbCache.WPF.cs b/FileDbCache/WPF/FileDbCache.WPF.cs index bf3ec8fa..56b4d955 100644 --- a/FileDbCache/WPF/FileDbCache.WPF.cs +++ b/FileDbCache/WPF/FileDbCache.WPF.cs @@ -147,9 +147,7 @@ namespace MapControl.Caching throw new ArgumentNullException("The parameter key must not be null."); } - var imageCacheItem = value as ImageCacheItem; - - if (imageCacheItem == null) + if (!(value is ImageCacheItem imageCacheItem)) { throw new ArgumentException("The parameter value must be a MapControl.Caching.ImageCacheItem instance."); } diff --git a/MBTiles/Shared/MBTileLayer.cs b/MBTiles/Shared/MBTileLayer.cs index 3133ea8f..95705204 100644 --- a/MBTiles/Shared/MBTileLayer.cs +++ b/MBTiles/Shared/MBTileLayer.cs @@ -57,26 +57,23 @@ namespace MapControl.MBTiles if (file != null) { var tileData = await MBTileData.CreateAsync(file); - int minZoom; - int maxZoom; - string s; - if (tileData.Metadata.TryGetValue("name", out s)) + if (tileData.Metadata.TryGetValue("name", out string sourceName)) { - SourceName = s; + SourceName = sourceName; } - if (tileData.Metadata.TryGetValue("description", out s)) + if (tileData.Metadata.TryGetValue("description", out string description)) { - Description = s; + Description = description; } - if (tileData.Metadata.TryGetValue("minzoom", out s) && int.TryParse(s, out minZoom)) + if (tileData.Metadata.TryGetValue("minzoom", out sourceName) && int.TryParse(sourceName, out int minZoom)) { MinZoomLevel = minZoom; } - if (tileData.Metadata.TryGetValue("maxzoom", out s) && int.TryParse(s, out maxZoom)) + if (tileData.Metadata.TryGetValue("maxzoom", out sourceName) && int.TryParse(sourceName, out int maxZoom)) { MaxZoomLevel = maxZoom; } diff --git a/MapControl/Shared/AzimuthalProjection.cs b/MapControl/Shared/AzimuthalProjection.cs index 1b77cfe2..efdfb67f 100644 --- a/MapControl/Shared/AzimuthalProjection.cs +++ b/MapControl/Shared/AzimuthalProjection.cs @@ -16,16 +16,9 @@ namespace MapControl /// public abstract class AzimuthalProjection : MapProjection { - public override bool IsNormalCylindrical - { - get { return false; } - } - public override Rect BoundingBoxToRect(BoundingBox boundingBox) { - var cbbox = boundingBox as CenteredBoundingBox; - - if (cbbox != null) + if (boundingBox is CenteredBoundingBox cbbox) { var center = LocationToMap(cbbox.Center); diff --git a/MapControl/Shared/EquirectangularProjection.cs b/MapControl/Shared/EquirectangularProjection.cs index 2ffd632c..5398afda 100644 --- a/MapControl/Shared/EquirectangularProjection.cs +++ b/MapControl/Shared/EquirectangularProjection.cs @@ -23,6 +23,11 @@ namespace MapControl CrsId = "EPSG:4326"; } + public override bool IsNormalCylindrical + { + get { return true; } + } + public override Vector GetRelativeScale(Location location) { return new Vector( diff --git a/MapControl/Shared/MapBase.cs b/MapControl/Shared/MapBase.cs index 0d2d131a..c452e6ba 100644 --- a/MapControl/Shared/MapBase.cs +++ b/MapControl/Shared/MapBase.cs @@ -388,8 +388,7 @@ namespace MapControl { Children.Remove(oldLayer); - var mapLayer = oldLayer as IMapLayer; - if (mapLayer != null) + if (oldLayer is IMapLayer mapLayer) { if (mapLayer.MapBackground != null) { @@ -406,8 +405,7 @@ namespace MapControl { Children.Insert(0, newLayer); - var mapLayer = newLayer as IMapLayer; - if (mapLayer != null) + if (newLayer is IMapLayer mapLayer) { if (mapLayer.MapBackground != null) { diff --git a/MapControl/Shared/MapPanel.cs b/MapControl/Shared/MapPanel.cs index c554759e..a44f4c48 100644 --- a/MapControl/Shared/MapPanel.cs +++ b/MapControl/Shared/MapPanel.cs @@ -228,9 +228,7 @@ namespace MapControl element.Height = rect.Height; element.Arrange(rect); - var rotateTransform = element.RenderTransform as RotateTransform; - - if (rotateTransform != null) + if (element.RenderTransform is RotateTransform rotateTransform) { rotateTransform.Angle = parentMap.ViewTransform.Rotation; } @@ -293,9 +291,7 @@ namespace MapControl private static void ParentMapPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e) { - var mapElement = obj as IMapElement; - - if (mapElement != null) + if (obj is IMapElement mapElement) { mapElement.ParentMap = e.NewValue as MapBase; } diff --git a/MapControl/Shared/MapProjection.cs b/MapControl/Shared/MapProjection.cs index ab593779..cfe7eabb 100644 --- a/MapControl/Shared/MapProjection.cs +++ b/MapControl/Shared/MapProjection.cs @@ -37,7 +37,7 @@ namespace MapControl /// public virtual bool IsNormalCylindrical { - get { return true; } + get { return false; } } /// diff --git a/MapControl/Shared/PolygonCollection.cs b/MapControl/Shared/PolygonCollection.cs index aefd1ab2..da7062f9 100644 --- a/MapControl/Shared/PolygonCollection.cs +++ b/MapControl/Shared/PolygonCollection.cs @@ -26,9 +26,7 @@ namespace MapControl protected override void InsertItem(int index, IEnumerable polygon) { - var observablePolygon = polygon as INotifyCollectionChanged; - - if (observablePolygon != null) + if (polygon is INotifyCollectionChanged observablePolygon) { CollectionChangedEventManager.AddListener(observablePolygon, this); } @@ -38,9 +36,7 @@ namespace MapControl protected override void SetItem(int index, IEnumerable polygon) { - var observablePolygon = this[index] as INotifyCollectionChanged; - - if (observablePolygon != null) + if (this[index] is INotifyCollectionChanged observablePolygon) { CollectionChangedEventManager.RemoveListener(observablePolygon, this); } @@ -50,9 +46,7 @@ namespace MapControl protected override void RemoveItem(int index) { - var observablePolygon = this[index] as INotifyCollectionChanged; - - if (observablePolygon != null) + if (this[index] is INotifyCollectionChanged observablePolygon) { CollectionChangedEventManager.RemoveListener(observablePolygon, this); } diff --git a/MapControl/Shared/WebMercatorProjection.cs b/MapControl/Shared/WebMercatorProjection.cs index d73355db..943ef97e 100644 --- a/MapControl/Shared/WebMercatorProjection.cs +++ b/MapControl/Shared/WebMercatorProjection.cs @@ -22,6 +22,11 @@ namespace MapControl CrsId = "EPSG:3857"; } + public override bool IsNormalCylindrical + { + get { return true; } + } + public override bool IsWebMercator { get { return true; } diff --git a/MapControl/Shared/WorldMercatorProjection.cs b/MapControl/Shared/WorldMercatorProjection.cs index 2008619f..564a3238 100644 --- a/MapControl/Shared/WorldMercatorProjection.cs +++ b/MapControl/Shared/WorldMercatorProjection.cs @@ -25,6 +25,11 @@ namespace MapControl CrsId = "EPSG:3395"; } + public override bool IsNormalCylindrical + { + get { return true; } + } + public override double MaxLatitude { get { return maxLatitude; } diff --git a/MapControl/UWP/ImageFileCache.UWP.cs b/MapControl/UWP/ImageFileCache.UWP.cs index 9aea9671..08200330 100644 --- a/MapControl/UWP/ImageFileCache.UWP.cs +++ b/MapControl/UWP/ImageFileCache.UWP.cs @@ -17,12 +17,7 @@ namespace MapControl.Caching public ImageFileCache(StorageFolder folder) { - if (folder == null) - { - throw new ArgumentNullException("The parameter rootFolder must not be null."); - } - - this.folder = folder; + this.folder = folder ?? throw new ArgumentNullException("The parameter rootFolder must not be null."); Debug.WriteLine("Created ImageFileCache in " + folder.Path); } diff --git a/MapControl/UWP/MapPanel.UWP.cs b/MapControl/UWP/MapPanel.UWP.cs index 6a840151..b140b80d 100644 --- a/MapControl/UWP/MapPanel.UWP.cs +++ b/MapControl/UWP/MapPanel.UWP.cs @@ -53,12 +53,9 @@ namespace MapControl private static MapBase FindParentMap(FrameworkElement element) { - var parent = VisualTreeHelper.GetParent(element) as FrameworkElement; - - return parent == null ? null - : ((parent as MapBase) - ?? (MapBase)element.GetValue(ParentMapProperty) - ?? FindParentMap(parent)); + return VisualTreeHelper.GetParent(element) is FrameworkElement parent + ? ((parent as MapBase) ?? (MapBase)element.GetValue(ParentMapProperty) ?? FindParentMap(parent)) + : null; } private static void SetViewPosition(FrameworkElement element, Point? viewPosition) diff --git a/MapControl/UWP/MapPath.UWP.cs b/MapControl/UWP/MapPath.UWP.cs index 294da581..1bc3befb 100644 --- a/MapControl/UWP/MapPath.UWP.cs +++ b/MapControl/UWP/MapPath.UWP.cs @@ -21,16 +21,14 @@ namespace MapControl protected void DataCollectionPropertyChanged(DependencyPropertyChangedEventArgs e) { - INotifyCollectionChanged collection; - - if ((collection = e.OldValue as INotifyCollectionChanged) != null) + if (e.OldValue is INotifyCollectionChanged oldCollection) { - collection.CollectionChanged -= DataCollectionChanged; + oldCollection.CollectionChanged -= DataCollectionChanged; } - if ((collection = e.NewValue as INotifyCollectionChanged) != null) + if (e.NewValue is INotifyCollectionChanged newCollection) { - collection.CollectionChanged += DataCollectionChanged; + newCollection.CollectionChanged += DataCollectionChanged; } UpdateData(); diff --git a/MapControl/UWP/Tile.UWP.cs b/MapControl/UWP/Tile.UWP.cs index 7a70a90f..30740773 100644 --- a/MapControl/UWP/Tile.UWP.cs +++ b/MapControl/UWP/Tile.UWP.cs @@ -18,9 +18,7 @@ namespace MapControl if (fadeIn && FadeDuration > TimeSpan.Zero) { - var bitmap = image as BitmapImage; - - if (bitmap?.UriSource != null) + if (image is BitmapImage bitmap && bitmap.UriSource != null) { bitmap.ImageOpened += BitmapImageOpened; bitmap.ImageFailed += BitmapImageFailed; diff --git a/MapControl/WPF/ImageFileCache.WPF.cs b/MapControl/WPF/ImageFileCache.WPF.cs index 88e1f61e..20b2bdaf 100644 --- a/MapControl/WPF/ImageFileCache.WPF.cs +++ b/MapControl/WPF/ImageFileCache.WPF.cs @@ -160,9 +160,8 @@ namespace MapControl.Caching throw new ArgumentNullException("The parameter key must not be null."); } - var imageCacheItem = value as ImageCacheItem; - if (imageCacheItem == null) + if (!(value is ImageCacheItem imageCacheItem)) { throw new ArgumentException("The parameter value must be a MapControl.Caching.ImageCacheItem instance."); } diff --git a/MapControl/WPF/MapPath.WPF.cs b/MapControl/WPF/MapPath.WPF.cs index 3feeff47..c68ec19c 100644 --- a/MapControl/WPF/MapPath.WPF.cs +++ b/MapControl/WPF/MapPath.WPF.cs @@ -35,16 +35,14 @@ namespace MapControl protected void DataCollectionPropertyChanged(DependencyPropertyChangedEventArgs e) { - INotifyCollectionChanged collection; - - if ((collection = e.OldValue as INotifyCollectionChanged) != null) + if (e.OldValue is INotifyCollectionChanged oldCollection) { - CollectionChangedEventManager.RemoveListener(collection, this); + CollectionChangedEventManager.RemoveListener(oldCollection, this); } - if ((collection = e.NewValue as INotifyCollectionChanged) != null) + if (e.NewValue is INotifyCollectionChanged newCollection) { - CollectionChangedEventManager.AddListener(collection, this); + CollectionChangedEventManager.AddListener(newCollection, this); } UpdateData(); diff --git a/MapControl/WPF/Tile.WPF.cs b/MapControl/WPF/Tile.WPF.cs index a0443f75..c35f88f0 100644 --- a/MapControl/WPF/Tile.WPF.cs +++ b/MapControl/WPF/Tile.WPF.cs @@ -17,9 +17,7 @@ namespace MapControl if (fadeIn && FadeDuration > TimeSpan.Zero) { - var bitmap = image as BitmapSource; - - if (bitmap != null && !bitmap.IsFrozen && bitmap.IsDownloading) + if (image is BitmapSource bitmap && !bitmap.IsFrozen && bitmap.IsDownloading) { bitmap.DownloadCompleted += BitmapDownloadCompleted; bitmap.DownloadFailed += BitmapDownloadFailed; diff --git a/MapImages/Shared/WorldFileImage.cs b/MapImages/Shared/WorldFileImage.cs index a7f28ccf..f24e00de 100644 --- a/MapImages/Shared/WorldFileImage.cs +++ b/MapImages/Shared/WorldFileImage.cs @@ -115,12 +115,11 @@ namespace MapControl.Images .Take(6) .Select((line, i) => { - double p; - if (!double.TryParse(line, NumberStyles.Float, CultureInfo.InvariantCulture, out p)) + if (!double.TryParse(line, NumberStyles.Float, CultureInfo.InvariantCulture, out double parameter)) { throw new ArgumentException("Failed parsing line " + (i + 1) + " in world file \"" + path + "\"."); } - return p; + return parameter; }) .ToList(); diff --git a/MapProjections/Shared/GeoApiProjection.cs b/MapProjections/Shared/GeoApiProjection.cs index 3ab74db5..d51c00ed 100644 --- a/MapProjections/Shared/GeoApiProjection.cs +++ b/MapProjections/Shared/GeoApiProjection.cs @@ -38,12 +38,7 @@ namespace MapControl.Projections get { return coordinateSystem; } set { - if (value == null) - { - throw new ArgumentNullException("The property value must not be null."); - } - - coordinateSystem = value; + coordinateSystem = value ?? throw new ArgumentNullException("The property value must not be null."); var transformFactory = new CoordinateTransformationFactory(); diff --git a/MapProjections/Shared/UtmProjection.cs b/MapProjections/Shared/UtmProjection.cs index 66188b36..d5f28107 100644 --- a/MapProjections/Shared/UtmProjection.cs +++ b/MapProjections/Shared/UtmProjection.cs @@ -24,10 +24,9 @@ namespace MapControl.Projections } var hemisphere = value[value.Length - 1]; - int zoneNumber; if ((hemisphere != 'N' && hemisphere != 'S') || - !int.TryParse(value.Substring(0, value.Length - 1), out zoneNumber)) + !int.TryParse(value.Substring(0, value.Length - 1), out int zoneNumber)) { throw new ArgumentException("Invalid UTM zone."); } diff --git a/SQLiteCache/WPF/SQLiteCache.WPF.cs b/SQLiteCache/WPF/SQLiteCache.WPF.cs index 272fb0b6..fe3f011b 100644 --- a/SQLiteCache/WPF/SQLiteCache.WPF.cs +++ b/SQLiteCache/WPF/SQLiteCache.WPF.cs @@ -169,9 +169,7 @@ namespace MapControl.Caching throw new ArgumentNullException("The parameter key must not be null."); } - var imageCacheItem = value as ImageCacheItem; - - if (imageCacheItem == null) + if (!(value is ImageCacheItem imageCacheItem)) { throw new ArgumentException("The parameter value must be a MapControl.Caching.ImageCacheItem instance."); }