From c0783efb4abe4bfac544cbd593afaadcf188cecb Mon Sep 17 00:00:00 2001 From: ClemensFischer Date: Mon, 15 Sep 2025 17:46:31 +0200 Subject: [PATCH] CsWinRT1028, C# LangVersion 12 --- MapControl/Shared/CenteredBoundingBox.cs | 15 +++----- MapControl/Shared/FilePath.cs | 6 ++-- MapControl/Shared/GroundOverlay.cs | 2 +- MapControl/Shared/ImageFileCache.cs | 2 +- MapControl/Shared/LocationCollection.cs | 2 +- MapControl/Shared/MapBorderPanel.cs | 2 +- MapControl/Shared/MapGraticule.cs | 21 ++++------- MapControl/Shared/MapMultiPolygon.cs | 2 +- MapControl/Shared/MapOverlaysPanel.cs | 2 +- MapControl/Shared/MapPolygon.cs | 2 +- MapControl/Shared/MapPolyline.cs | 2 +- MapControl/Shared/MapScale.cs | 2 +- MapControl/Shared/MapTileLayer.cs | 2 +- MapControl/Shared/PolygonCollection.cs | 2 +- MapControl/Shared/Tile.cs | 19 ++++------ MapControl/Shared/TileCollection.cs | 2 +- MapControl/Shared/TileMatrix.cs | 21 ++++------- MapControl/Shared/TypeConverters.cs | 8 ++--- MapControl/Shared/ViewportChangedEventArgs.cs | 12 ++----- MapControl/Shared/WmsImageLayer.cs | 2 +- MapControl/Shared/WmtsTileLayer.cs | 4 +-- MapControl/Shared/WmtsTileMatrix.cs | 36 +++++++------------ MapControl/Shared/WmtsTileMatrixLayer.cs | 2 +- MapControl/WPF/MapControl.WPF.csproj | 2 +- MapControl/WinUI/MapContentControl.WinUI.cs | 4 +-- MapControl/WinUI/MapPolypoint.WinUI.cs | 2 +- .../WpfApplication/WpfApplication.csproj | 8 ++--- 27 files changed, 67 insertions(+), 119 deletions(-) diff --git a/MapControl/Shared/CenteredBoundingBox.cs b/MapControl/Shared/CenteredBoundingBox.cs index 089263fe..df0bdb24 100644 --- a/MapControl/Shared/CenteredBoundingBox.cs +++ b/MapControl/Shared/CenteredBoundingBox.cs @@ -2,17 +2,10 @@ namespace MapControl { - public class CenteredBoundingBox : BoundingBox + public class CenteredBoundingBox(Location center, double width, double height) : BoundingBox { - public CenteredBoundingBox(Location center, double width, double height) - { - Center = center; - Width = Math.Max(width, 0d); - Height = Math.Max(height, 0d); - } - - public override Location Center { get; } - public override double Width { get; } - public override double Height { get; } + public override Location Center { get; } = center; + public override double Width { get; } = Math.Max(width, 0d); + public override double Height { get; } = Math.Max(height, 0d); } } diff --git a/MapControl/Shared/FilePath.cs b/MapControl/Shared/FilePath.cs index 506bda90..5c602820 100644 --- a/MapControl/Shared/FilePath.cs +++ b/MapControl/Shared/FilePath.cs @@ -6,10 +6,10 @@ namespace MapControl { public static string GetFullPath(string path) { -#if NET6_0_OR_GREATER - return Path.GetFullPath(path, System.AppDomain.CurrentDomain.BaseDirectory); -#else +#if NETFRAMEWORK return Path.GetFullPath(path); +#else + return Path.GetFullPath(path, System.AppDomain.CurrentDomain.BaseDirectory); #endif } } diff --git a/MapControl/Shared/GroundOverlay.cs b/MapControl/Shared/GroundOverlay.cs index a1c41f80..3204efb9 100644 --- a/MapControl/Shared/GroundOverlay.cs +++ b/MapControl/Shared/GroundOverlay.cs @@ -26,7 +26,7 @@ using Avalonia.Media; namespace MapControl { - public class GroundOverlay : MapPanel + public partial class GroundOverlay : MapPanel { private class ImageOverlay { diff --git a/MapControl/Shared/ImageFileCache.cs b/MapControl/Shared/ImageFileCache.cs index e71cd217..9467db7d 100644 --- a/MapControl/Shared/ImageFileCache.cs +++ b/MapControl/Shared/ImageFileCache.cs @@ -23,7 +23,7 @@ namespace MapControl.Caching /// IDistributedCache implementation that creates a single file per cache entry. /// The cache expiration time is stored in the file's CreationTime property. /// - public sealed class ImageFileCache : IDistributedCache, IDisposable + public sealed partial class ImageFileCache : IDistributedCache, IDisposable { private readonly MemoryDistributedCache memoryCache; private readonly DirectoryInfo rootDirectory; diff --git a/MapControl/Shared/LocationCollection.cs b/MapControl/Shared/LocationCollection.cs index 39f9687a..18ed92b6 100644 --- a/MapControl/Shared/LocationCollection.cs +++ b/MapControl/Shared/LocationCollection.cs @@ -13,7 +13,7 @@ namespace MapControl #else [System.ComponentModel.TypeConverter(typeof(LocationCollectionConverter))] #endif - public class LocationCollection : List + public partial class LocationCollection : List { public LocationCollection() { diff --git a/MapControl/Shared/MapBorderPanel.cs b/MapControl/Shared/MapBorderPanel.cs index f99dc0b0..14a0747e 100644 --- a/MapControl/Shared/MapBorderPanel.cs +++ b/MapControl/Shared/MapBorderPanel.cs @@ -16,7 +16,7 @@ namespace MapControl /// Such elements are arranged at a distance of BorderWidth/2 from the edges of the /// MapBorderPanel in direction of their original azimuth from the map center. /// - public class MapBorderPanel : MapPanel + public partial class MapBorderPanel : MapPanel { public static readonly DependencyProperty BorderWidthProperty = DependencyPropertyHelper.Register(nameof(BorderWidth)); diff --git a/MapControl/Shared/MapGraticule.cs b/MapControl/Shared/MapGraticule.cs index 72188be3..92cd6345 100644 --- a/MapControl/Shared/MapGraticule.cs +++ b/MapControl/Shared/MapGraticule.cs @@ -24,22 +24,13 @@ namespace MapControl /// public partial class MapGraticule { - private class Label + private class Label(string latText, string lonText, double x, double y, double rotation) { - public Label(string latText, string lonText, double x, double y, double rotation) - { - LatitudeText = latText; - LongitudeText = lonText; - X = x; - Y = y; - Rotation = rotation; - } - - public string LatitudeText { get; } - public string LongitudeText { get; } - public double X { get; } - public double Y { get; } - public double Rotation { get; } + public string LatitudeText { get; } = latText; + public string LongitudeText { get; } = lonText; + public double X { get; } = x; + public double Y { get; } = y; + public double Rotation { get; } = rotation; } private const double LineInterpolationResolution = 2d; diff --git a/MapControl/Shared/MapMultiPolygon.cs b/MapControl/Shared/MapMultiPolygon.cs index 9fa47f61..adcb0a07 100644 --- a/MapControl/Shared/MapMultiPolygon.cs +++ b/MapControl/Shared/MapMultiPolygon.cs @@ -17,7 +17,7 @@ namespace MapControl /// for the Polygons property if collection changes of the property itself and its /// elements are both supposed to trigger UI updates. /// - public class MapMultiPolygon : MapPolypoint + public partial class MapMultiPolygon : MapPolypoint { public static readonly DependencyProperty PolygonsProperty = DependencyPropertyHelper.Register>>(nameof(Polygons), null, diff --git a/MapControl/Shared/MapOverlaysPanel.cs b/MapControl/Shared/MapOverlaysPanel.cs index 8f78451a..a2b5cb7c 100644 --- a/MapControl/Shared/MapOverlaysPanel.cs +++ b/MapControl/Shared/MapOverlaysPanel.cs @@ -16,7 +16,7 @@ namespace MapControl /// /// A MapPanel with a collection of GroundOverlay or GeoImage children. /// - public class MapOverlaysPanel : MapPanel + public partial class MapOverlaysPanel : MapPanel { public static readonly DependencyProperty SourcePathsProperty = DependencyPropertyHelper.Register>(nameof(SourcePaths), null, diff --git a/MapControl/Shared/MapPolygon.cs b/MapControl/Shared/MapPolygon.cs index b5721247..8b7fe830 100644 --- a/MapControl/Shared/MapPolygon.cs +++ b/MapControl/Shared/MapPolygon.cs @@ -12,7 +12,7 @@ namespace MapControl /// /// A polygon defined by a collection of Locations. /// - public class MapPolygon : MapPolypoint + public partial class MapPolygon : MapPolypoint { public static readonly DependencyProperty LocationsProperty = DependencyPropertyHelper.Register>(nameof(Locations), null, diff --git a/MapControl/Shared/MapPolyline.cs b/MapControl/Shared/MapPolyline.cs index 544cb1c4..aabc3331 100644 --- a/MapControl/Shared/MapPolyline.cs +++ b/MapControl/Shared/MapPolyline.cs @@ -12,7 +12,7 @@ namespace MapControl /// /// A polyline defined by a collection of Locations. /// - public class MapPolyline : MapPolypoint + public partial class MapPolyline : MapPolypoint { public static readonly DependencyProperty LocationsProperty = DependencyPropertyHelper.Register>(nameof(Locations), null, diff --git a/MapControl/Shared/MapScale.cs b/MapControl/Shared/MapScale.cs index e37ed603..6ffac495 100644 --- a/MapControl/Shared/MapScale.cs +++ b/MapControl/Shared/MapScale.cs @@ -34,7 +34,7 @@ namespace MapControl /// /// Draws a map scale overlay. /// - public class MapScale : MapPanel + public partial class MapScale : MapPanel { public static readonly DependencyProperty PaddingProperty = DependencyPropertyHelper.Register(nameof(Padding), new Thickness(4)); diff --git a/MapControl/Shared/MapTileLayer.cs b/MapControl/Shared/MapTileLayer.cs index 576586a2..d79bc0d2 100644 --- a/MapControl/Shared/MapTileLayer.cs +++ b/MapControl/Shared/MapTileLayer.cs @@ -20,7 +20,7 @@ namespace MapControl /// /// Displays a standard Web Mercator map tile grid, e.g. an OpenStreetMap tile grid. /// - public class MapTileLayer : MapTileLayerBase + public partial class MapTileLayer : MapTileLayerBase { public static readonly DependencyProperty MinZoomLevelProperty = DependencyPropertyHelper.Register(nameof(MinZoomLevel), 0); diff --git a/MapControl/Shared/PolygonCollection.cs b/MapControl/Shared/PolygonCollection.cs index 018b8583..17f623d4 100644 --- a/MapControl/Shared/PolygonCollection.cs +++ b/MapControl/Shared/PolygonCollection.cs @@ -10,7 +10,7 @@ namespace MapControl /// listener to each element that implements INotifyCollectionChanged and, when such an element changes, /// fires its own CollectionChanged event with NotifyCollectionChangedAction.Replace for that element. /// - public class PolygonCollection : ObservableCollection> + public partial class PolygonCollection : ObservableCollection> { private void PolygonChanged(object sender, NotifyCollectionChangedEventArgs e) { diff --git a/MapControl/Shared/Tile.cs b/MapControl/Shared/Tile.cs index 19365850..fdabcef1 100644 --- a/MapControl/Shared/Tile.cs +++ b/MapControl/Shared/Tile.cs @@ -14,22 +14,15 @@ using Avalonia.Media; namespace MapControl { - public partial class Tile + public partial class Tile(int zoomLevel, int x, int y, int columnCount) { - public Tile(int zoomLevel, int x, int y, int columnCount) - { - ZoomLevel = zoomLevel; - X = x; - Y = y; - Column = ((x % columnCount) + columnCount) % columnCount; - } + public int ZoomLevel { get; } = zoomLevel; + public int X { get; } = x; + public int Y { get; } = y; + public int Column { get; } = ((x % columnCount) + columnCount) % columnCount; + public int Row => Y; public Image Image { get; } = new Image { Stretch = Stretch.Fill }; - public int ZoomLevel { get; } - public int X { get; } - public int Y { get; } - public int Column { get; } - public int Row => Y; public bool IsPending { get; set; } = true; } } diff --git a/MapControl/Shared/TileCollection.cs b/MapControl/Shared/TileCollection.cs index d13d4935..58257e99 100644 --- a/MapControl/Shared/TileCollection.cs +++ b/MapControl/Shared/TileCollection.cs @@ -3,7 +3,7 @@ using System.Linq; namespace MapControl { - public class TileCollection : List + public partial class TileCollection : List { /// /// Adds existing Tiles from the source collection or newly created Tiles to fill the specified tile matrix. diff --git a/MapControl/Shared/TileMatrix.cs b/MapControl/Shared/TileMatrix.cs index c690a6e6..2ecf4dd5 100644 --- a/MapControl/Shared/TileMatrix.cs +++ b/MapControl/Shared/TileMatrix.cs @@ -1,20 +1,11 @@ namespace MapControl { - public class TileMatrix + public class TileMatrix(int zoomLevel, int xMin, int yMin, int xMax, int yMax) { - public TileMatrix(int zoomLevel, int xMin, int yMin, int xMax, int yMax) - { - ZoomLevel = zoomLevel; - XMin = xMin; - YMin = yMin; - XMax = xMax; - YMax = yMax; - } - - public int ZoomLevel { get; } - public int XMin { get; } - public int YMin { get; } - public int XMax { get; } - public int YMax { get; } + public int ZoomLevel { get; } = zoomLevel; + public int XMin { get; } = xMin; + public int YMin { get; } = yMin; + public int XMax { get; } = xMax; + public int YMax { get; } = yMax; } } diff --git a/MapControl/Shared/TypeConverters.cs b/MapControl/Shared/TypeConverters.cs index 348b0e7f..010d241f 100644 --- a/MapControl/Shared/TypeConverters.cs +++ b/MapControl/Shared/TypeConverters.cs @@ -18,7 +18,7 @@ using ConverterCulture = System.Globalization.CultureInfo; namespace MapControl { - public class LocationConverter : TypeConverter, IValueConverter + public partial class LocationConverter : TypeConverter, IValueConverter { public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) { @@ -41,7 +41,7 @@ namespace MapControl } } - public class LocationCollectionConverter : TypeConverter, IValueConverter + public partial class LocationCollectionConverter : TypeConverter, IValueConverter { public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) { @@ -64,7 +64,7 @@ namespace MapControl } } - public class BoundingBoxConverter : TypeConverter, IValueConverter + public partial class BoundingBoxConverter : TypeConverter, IValueConverter { public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) { @@ -87,7 +87,7 @@ namespace MapControl } } - public class TileSourceConverter : TypeConverter, IValueConverter + public partial class TileSourceConverter : TypeConverter, IValueConverter { public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) { diff --git a/MapControl/Shared/ViewportChangedEventArgs.cs b/MapControl/Shared/ViewportChangedEventArgs.cs index 1f5392e5..d7e220f9 100644 --- a/MapControl/Shared/ViewportChangedEventArgs.cs +++ b/MapControl/Shared/ViewportChangedEventArgs.cs @@ -2,25 +2,19 @@ namespace MapControl { - public class ViewportChangedEventArgs : EventArgs + public class ViewportChangedEventArgs(bool projectionChanged = false, bool transformCenterChanged = false) : EventArgs { - public ViewportChangedEventArgs(bool projectionChanged = false, bool transformCenterChanged = false) - { - ProjectionChanged = projectionChanged; - TransformCenterChanged = transformCenterChanged; - } - /// /// Indicates that the map projection has changed. Used to control when /// a MapTileLayer or a MapImageLayer should be updated immediately, /// or MapPath Data in projected map coordinates should be recalculated. /// - public bool ProjectionChanged { get; } + public bool ProjectionChanged { get; } = projectionChanged; /// /// Indicates that the view transform center has moved across 180° longitude. /// Used to control when a MapTileLayer should be updated immediately. /// - public bool TransformCenterChanged { get; } + public bool TransformCenterChanged { get; } = transformCenterChanged; } } diff --git a/MapControl/Shared/WmsImageLayer.cs b/MapControl/Shared/WmsImageLayer.cs index 136e4b0e..4c00731c 100644 --- a/MapControl/Shared/WmsImageLayer.cs +++ b/MapControl/Shared/WmsImageLayer.cs @@ -23,7 +23,7 @@ namespace MapControl /// /// Displays a single map image from a Web Map Service (WMS). /// - public class WmsImageLayer : MapImageLayer + public partial class WmsImageLayer : MapImageLayer { private static ILogger logger; private static ILogger Logger => logger ??= ImageLoader.LoggerFactory?.CreateLogger(); diff --git a/MapControl/Shared/WmtsTileLayer.cs b/MapControl/Shared/WmtsTileLayer.cs index 2ae12320..8f57aa5b 100644 --- a/MapControl/Shared/WmtsTileLayer.cs +++ b/MapControl/Shared/WmtsTileLayer.cs @@ -20,7 +20,7 @@ namespace MapControl /// /// Displays map tiles from a Web Map Tile Service (WMTS). /// - public class WmtsTileLayer : MapTileLayerBase + public partial class WmtsTileLayer : MapTileLayerBase { private static ILogger logger; private static ILogger Logger => logger ??= ImageLoader.LoggerFactory?.CreateLogger(); @@ -70,7 +70,7 @@ namespace MapControl public IEnumerable ChildLayers => Children.Cast(); - public Dictionary TileMatrixSets { get; } = new Dictionary(); + public Dictionary TileMatrixSets { get; } = []; protected virtual WmtsTileSource CreateTileSource(string uriTemplate) => new WmtsTileSource { UriTemplate = uriTemplate }; diff --git a/MapControl/Shared/WmtsTileMatrix.cs b/MapControl/Shared/WmtsTileMatrix.cs index 8ea2d88c..b065984b 100644 --- a/MapControl/Shared/WmtsTileMatrix.cs +++ b/MapControl/Shared/WmtsTileMatrix.cs @@ -6,29 +6,19 @@ using Avalonia; namespace MapControl { - public class WmtsTileMatrix + // See 07-057r7_Web_Map_Tile_Service_Standard.pdf, section 6.1.a, page 8: + // "standardized rendering pixel size" is 0.28 mm + // + public class WmtsTileMatrix( + string identifier, double scaleDenominator, Point topLeft, + int tileWidth, int tileHeight, int matrixWidth, int matrixHeight) { - // See 07-057r7_Web_Map_Tile_Service_Standard.pdf, section 6.1.a, page 8: - // "standardized rendering pixel size" is 0.28 mm - - public WmtsTileMatrix(string identifier, double scaleDenominator, Point topLeft, - int tileWidth, int tileHeight, int matrixWidth, int matrixHeight) - { - Identifier = identifier; - Scale = 1 / (scaleDenominator * 0.00028); // 0.28 mm - TopLeft = topLeft; - TileWidth = tileWidth; - TileHeight = tileHeight; - MatrixWidth = matrixWidth; - MatrixHeight = matrixHeight; - } - - public string Identifier { get; } - public double Scale { get; } - public Point TopLeft { get; } - public int TileWidth { get; } - public int TileHeight { get; } - public int MatrixWidth { get; } - public int MatrixHeight { get; } + public string Identifier { get; } = identifier; + public double Scale { get; } = 1 / (scaleDenominator * 0.00028); // 0.28 mm + public Point TopLeft { get; } = topLeft; + public int TileWidth { get; } = tileWidth; + public int TileHeight { get; } = tileHeight; + public int MatrixWidth { get; } = matrixWidth; + public int MatrixHeight { get; } = matrixHeight; } } diff --git a/MapControl/Shared/WmtsTileMatrixLayer.cs b/MapControl/Shared/WmtsTileMatrixLayer.cs index e9199302..3e20c123 100644 --- a/MapControl/Shared/WmtsTileMatrixLayer.cs +++ b/MapControl/Shared/WmtsTileMatrixLayer.cs @@ -19,7 +19,7 @@ using Avalonia.Media; namespace MapControl { - public class WmtsTileMatrixLayer : Panel + public partial class WmtsTileMatrixLayer : Panel { // zoomLevel is index of tileMatrix in a WmtsTileMatrixSet.TileMatrixes list. // diff --git a/MapControl/WPF/MapControl.WPF.csproj b/MapControl/WPF/MapControl.WPF.csproj index e9682346..78afa87e 100644 --- a/MapControl/WPF/MapControl.WPF.csproj +++ b/MapControl/WPF/MapControl.WPF.csproj @@ -1,7 +1,7 @@  net9.0-windows;net462 - 8.0 + 12.0 true WPF MapControl diff --git a/MapControl/WinUI/MapContentControl.WinUI.cs b/MapControl/WinUI/MapContentControl.WinUI.cs index 40f41544..a4b40e3d 100644 --- a/MapControl/WinUI/MapContentControl.WinUI.cs +++ b/MapControl/WinUI/MapContentControl.WinUI.cs @@ -13,7 +13,7 @@ namespace MapControl /// /// ContentControl placed on a MapPanel at a geographic location specified by the Location property. /// - public class MapContentControl : ContentControl + public partial class MapContentControl : ContentControl { public static readonly DependencyProperty AutoCollapseProperty = DependencyPropertyHelper.Register(nameof(AutoCollapse), false, @@ -79,7 +79,7 @@ namespace MapControl /// /// MapContentControl with a Pushpin Style. /// - public class Pushpin : MapContentControl + public partial class Pushpin : MapContentControl { public Pushpin() { diff --git a/MapControl/WinUI/MapPolypoint.WinUI.cs b/MapControl/WinUI/MapPolypoint.WinUI.cs index 67ae5377..168dd6c2 100644 --- a/MapControl/WinUI/MapPolypoint.WinUI.cs +++ b/MapControl/WinUI/MapPolypoint.WinUI.cs @@ -16,7 +16,7 @@ namespace MapControl /// /// Base class of MapPolyline and MapPolygon. /// - public class MapPolypoint : MapPath + public partial class MapPolypoint : MapPath { public static readonly DependencyProperty FillRuleProperty = DependencyPropertyHelper.Register(nameof(FillRule), FillRule.EvenOdd, diff --git a/SampleApps/WpfApplication/WpfApplication.csproj b/SampleApps/WpfApplication/WpfApplication.csproj index 51ec6272..328c1bb3 100644 --- a/SampleApps/WpfApplication/WpfApplication.csproj +++ b/SampleApps/WpfApplication/WpfApplication.csproj @@ -25,15 +25,11 @@ - - + + - - - -