From 87dd9f646d96fcd7f6d30ebf59395b424f5d8cab Mon Sep 17 00:00:00 2001 From: Valentas Date: Mon, 3 Apr 2023 08:57:05 +0300 Subject: [PATCH] Fixed couple warnings for nulabiliyt --- .../Maps/DirectionsRequest.cs | 8 ++-- GoogleMapsComponents/Maps/DirectionsStep.cs | 18 ++++----- .../Maps/Extension/CircleList.cs | 38 ++++++++++--------- .../Maps/Extension/ListableEntityListBase.cs | 4 +- .../Pages/MapCircleListPage.razor.cs | 24 ++++++------ 5 files changed, 48 insertions(+), 44 deletions(-) diff --git a/GoogleMapsComponents/Maps/DirectionsRequest.cs b/GoogleMapsComponents/Maps/DirectionsRequest.cs index 0dc7c817..c0271d69 100644 --- a/GoogleMapsComponents/Maps/DirectionsRequest.cs +++ b/GoogleMapsComponents/Maps/DirectionsRequest.cs @@ -37,7 +37,7 @@ public class DirectionsRequest /// Settings that apply only to requests where travelMode is DRIVING. /// This object will have no effect for other travel modes. /// - public DrivingOptions DrivingOptions { get; set; } + public DrivingOptions? DrivingOptions { get; set; } /// /// If set to true, the DirectionsService will attempt to re-order the supplied intermediate waypoints to minimize overall cost of the route. @@ -62,13 +62,13 @@ public class DirectionsRequest /// Region code used as a bias for geocoding requests. /// Optional. /// - public string Region { get; set; } + public string? Region { get; set; } /// /// Settings that apply only to requests where travelMode is TRANSIT. /// This object will have no effect for other travel modes. /// - public TransitOptions TransitOptions { get; set; } + public TransitOptions? TransitOptions { get; set; } /// /// Type of routing requested. @@ -88,6 +88,6 @@ public class DirectionsRequest /// See the developer's guide for the maximum number of waypoints allowed. /// Waypoints are not supported for transit directions. Optional. /// - public IEnumerable Waypoints { get; set; } + public IEnumerable? Waypoints { get; set; } } } diff --git a/GoogleMapsComponents/Maps/DirectionsStep.cs b/GoogleMapsComponents/Maps/DirectionsStep.cs index baac718b..c654a073 100644 --- a/GoogleMapsComponents/Maps/DirectionsStep.cs +++ b/GoogleMapsComponents/Maps/DirectionsStep.cs @@ -14,40 +14,40 @@ public class DirectionsStep /// The distance covered by this step. /// This property may be undefined as the distance may be unknown. /// - public Distance Distance { get; set; } + public Distance? Distance { get; set; } /// /// The typical time required to perform this step in seconds and in text form. /// This property may be undefined as the duration may be unknown. /// - public Duration Duration { get; set; } + public Duration? Duration { get; set; } /// /// The ending location of this step. /// - public LatLngLiteral EndLocation { get; set; } + public LatLngLiteral? EndLocation { get; set; } /// /// Instructions for this step. /// - public string Instructions { get; set; } + public string? Instructions { get; set; } /// /// The starting location of this step. /// - public LatLngLiteral StartLocation { get; set; } + public LatLngLiteral? StartLocation { get; set; } /// /// Sub-steps of this step. /// Specified for non-transit sections of transit routes. /// - public IEnumerable Steps { get; set; } + public IEnumerable? Steps { get; set; } /// /// Transit-specific details about this step. /// This property will be undefined unless the travel mode of this step is TRANSIT. /// - public TransitDetails Transit { get; set; } + public TransitDetails? Transit { get; set; } /// /// The mode of travel used in this step. @@ -56,12 +56,12 @@ public class DirectionsStep [JsonPropertyName("lat_lngs")] - public IEnumerable LatLngs { get; set; } + public IEnumerable? LatLngs { get; set; } /// /// A sequence of LatLngs describing the course of this step. /// [JsonPropertyName("path")] - public IEnumerable Path { get; set; } + public IEnumerable? Path { get; set; } } } diff --git a/GoogleMapsComponents/Maps/Extension/CircleList.cs b/GoogleMapsComponents/Maps/Extension/CircleList.cs index 402c33e3..d2cc0baf 100644 --- a/GoogleMapsComponents/Maps/Extension/CircleList.cs +++ b/GoogleMapsComponents/Maps/Extension/CircleList.cs @@ -26,15 +26,15 @@ public class CircleList : ListableEntityListBase /// new instance of CircleList class will be returned with its Circles dictionary member populated with the corresponding results public static async Task CreateAsync(IJSRuntime jsRuntime, Dictionary opts) { - JsObjectRef jsObjectRef = new JsObjectRef(jsRuntime, Guid.NewGuid()); + var jsObjectRef = new JsObjectRef(jsRuntime, Guid.NewGuid()); - CircleList obj; Dictionary jsObjectRefs = await JsObjectRef.CreateMultipleAsync( jsRuntime, "google.maps.Circle", opts.ToDictionary(e => e.Key, e => (object)e.Value)); - Dictionary objs = jsObjectRefs.ToDictionary(e => e.Key, e => new Circle(e.Value)); - obj = new CircleList(jsObjectRef, objs); + + var objs = jsObjectRefs.ToDictionary(e => e.Key, e => new Circle(e.Value)); + var obj = new CircleList(jsObjectRef, objs); return obj; } @@ -48,10 +48,14 @@ public static async Task CreateAsync(IJSRuntime jsRuntime, Dictionar /// /// /// + /// /// /// The managed list. Assign to the variable you used as parameter. /// - public static async Task SyncAsync(CircleList list, IJSRuntime jsRuntime, Dictionary opts, Action clickCallback = null) + public static async Task SyncAsync(CircleList? list, + IJSRuntime jsRuntime, + Dictionary opts, + Action? clickCallback = null) { if (opts.Count == 0) { @@ -68,7 +72,7 @@ public static async Task SyncAsync(CircleList list, IJSRuntime jsRun list = await CircleList.CreateAsync(jsRuntime, new Dictionary()); if (clickCallback != null) { - list.EntityClicked += (sender, e) => + list.EntityClicked += (_, e) => { clickCallback(e.MouseEvent, e.Key, e.Entity); }; @@ -104,9 +108,9 @@ public async Task AddMultipleAsync(Dictionary opts) await base.AddMultipleAsync(opts, "google.maps.Circle"); } - public Task> GetBounds(List filterKeys = null) + public Task> GetBounds(List? filterKeys = null) { - List matchingKeys = ComputeMathingKeys(filterKeys); + var matchingKeys = ComputeMathingKeys(filterKeys); if (matchingKeys.Any()) { @@ -123,9 +127,9 @@ public Task> GetBounds(List filt } } - public Task> GetCenters(List filterKeys = null) + public Task> GetCenters(List? filterKeys = null) { - List matchingKeys = ComputeMathingKeys(filterKeys); + var matchingKeys = ComputeMathingKeys(filterKeys); if (matchingKeys.Any()) { @@ -142,9 +146,9 @@ public Task> GetCenters(List filterKey } } - public Task> GetEditables(List filterKeys = null) + public Task> GetEditables(List? filterKeys = null) { - List matchingKeys = ComputeMathingKeys(filterKeys); + var matchingKeys = ComputeMathingKeys(filterKeys); if (matchingKeys.Any()) { @@ -161,9 +165,9 @@ public Task> GetEditables(List filterKeys = nul } } - public Task> GetRadiuses(List filterKeys = null) + public Task> GetRadiuses(List? filterKeys = null) { - List matchingKeys = ComputeMathingKeys(filterKeys); + var matchingKeys = ComputeMathingKeys(filterKeys); if (matchingKeys.Any()) { @@ -182,7 +186,7 @@ public Task> GetRadiuses(List filterKeys = nu public Task SetCenters(Dictionary centers) { - Dictionary dictArgs = centers.ToDictionary(e => Circles[e.Key].Guid, e => (object)e.Value); + var dictArgs = centers.ToDictionary(e => Circles[e.Key].Guid, e => (object)e.Value); return _jsObjectRef.InvokeMultipleAsync( "setCenter", dictArgs); @@ -190,7 +194,7 @@ public Task SetCenters(Dictionary centers) public Task SetEditables(Dictionary editables) { - Dictionary dictArgs = editables.ToDictionary(e => Circles[e.Key].Guid, e => (object)e.Value); + var dictArgs = editables.ToDictionary(e => Circles[e.Key].Guid, e => (object)e.Value); return _jsObjectRef.InvokeMultipleAsync( "setEditable", dictArgs); @@ -198,7 +202,7 @@ public Task SetEditables(Dictionary editables) public Task SetRadiuses(Dictionary radiuses) { - Dictionary dictArgs = radiuses.ToDictionary(e => Circles[e.Key].Guid, e => (object)e.Value); + var dictArgs = radiuses.ToDictionary(e => Circles[e.Key].Guid, e => (object)e.Value); return _jsObjectRef.InvokeMultipleAsync( "setRadius", dictArgs); diff --git a/GoogleMapsComponents/Maps/Extension/ListableEntityListBase.cs b/GoogleMapsComponents/Maps/Extension/ListableEntityListBase.cs index 92044298..317e220b 100644 --- a/GoogleMapsComponents/Maps/Extension/ListableEntityListBase.cs +++ b/GoogleMapsComponents/Maps/Extension/ListableEntityListBase.cs @@ -192,7 +192,7 @@ public virtual async Task RemoveMultipleAsync(List guids) //Find the eventual match between required keys (if any) and yet stored markers key (if any) //If filterKeys is null or empty all keys are returned //Otherwise only eventually yet stored marker keys that matches with filterKeys - protected virtual List ComputeMathingKeys(List filterKeys = null) + protected virtual List ComputeMathingKeys(List? filterKeys = null) { List matchingKeys; @@ -202,7 +202,7 @@ protected virtual List ComputeMathingKeys(List filterKeys = null } else { - matchingKeys = BaseListableEntities.Keys.Where(e => filterKeys.Contains(e)).ToList(); + matchingKeys = BaseListableEntities.Keys.Where(filterKeys.Contains).ToList(); } return matchingKeys; diff --git a/ServerSideDemo/Pages/MapCircleListPage.razor.cs b/ServerSideDemo/Pages/MapCircleListPage.razor.cs index de921abd..b756868d 100644 --- a/ServerSideDemo/Pages/MapCircleListPage.razor.cs +++ b/ServerSideDemo/Pages/MapCircleListPage.razor.cs @@ -1,10 +1,10 @@ -using System; -using System.Collections.Generic; -using System.Threading.Tasks; -using GoogleMapsComponents; +using GoogleMapsComponents; using GoogleMapsComponents.Maps; using GoogleMapsComponents.Maps.Extension; using Microsoft.AspNetCore.Components; +using System; +using System.Collections.Generic; +using System.Threading.Tasks; namespace ServerSideDemo.Pages { @@ -37,8 +37,8 @@ protected override void OnInitialized() /// private async void CreateBunchOfCircles() { - int howMany = this.bunchsize; - var bounds = await this.map1.InteropObject.GetBounds(); + int howMany = bunchsize; + var bounds = await map1.InteropObject.GetBounds(); double maxRadius = (bounds.North - bounds.South) * 111111.0 / (10 + Math.Sqrt(howMany)); var colors = new string[] { "#FFFFFF", "#9132D1", "#FFD800", "#846A00", "#AAC643", "#C96A00", "#B200FF", "#CD6A00", "#00A321", "#7F6420" }; var rnd = new Random(); @@ -47,7 +47,7 @@ private async void CreateBunchOfCircles() var color = colors[rnd.Next(0, colors.Length)]; var circleOptions = new CircleOptions { - Map = this.map1.InteropObject, + Map = map1.InteropObject, Center = new LatLngLiteral { Lat = bounds.South + rnd.NextDouble() * (bounds.North - bounds.South), Lng = bounds.West + rnd.NextDouble() * (bounds.East - bounds.West) }, Radius = (rnd.NextDouble() + 0.2) / 1.2 * maxRadius, StrokeColor = color, @@ -58,18 +58,18 @@ private async void CreateBunchOfCircles() Visible = true, ZIndex = 1000000, }; - this.circleOptionsByRef[(++this.lastId).ToString()] = circleOptions; + circleOptionsByRef[(++lastId).ToString()] = circleOptions; } - await this.RefreshCircleList(); + await RefreshCircleList(); } private async Task RefreshCircleList() { - this.circleList = await CircleList.SyncAsync(this.circleList, this.map1.JsRuntime, circleOptionsByRef, async (ev, sKey, entity) => + circleList = await CircleList.SyncAsync(circleList, map1.JsRuntime, circleOptionsByRef, async (ev, sKey, entity) => { // Circle has been clicked --> delete it. - this.circleOptionsByRef.Remove(sKey); - await this.RefreshCircleList(); + circleOptionsByRef.Remove(sKey); + await RefreshCircleList(); }); } }