From a43a463964d74abba11ca247550b7e44f7294638 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 24 May 2021 04:17:59 +0000 Subject: [PATCH 01/18] Bump DynamicData from 7.1.16 to 7.1.17 Bumps [DynamicData](https://github.com/reactiveui/DynamicData) from 7.1.16 to 7.1.17. - [Release notes](https://github.com/reactiveui/DynamicData/releases) - [Changelog](https://github.com/reactivemarbles/DynamicData/blob/main/ReleaseNotes.md) - [Commits](https://github.com/reactiveui/DynamicData/compare/7.1.16...7.1.17) Signed-off-by: dependabot[bot] --- .../MvvmScarletToolkit.Incubator.csproj | 2 +- .../MvvmScarletToolkit.Observables.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/MvvmScarletToolkit.Incubator/MvvmScarletToolkit.Incubator.csproj b/src/MvvmScarletToolkit.Incubator/MvvmScarletToolkit.Incubator.csproj index 528bd455..d9fba428 100644 --- a/src/MvvmScarletToolkit.Incubator/MvvmScarletToolkit.Incubator.csproj +++ b/src/MvvmScarletToolkit.Incubator/MvvmScarletToolkit.Incubator.csproj @@ -8,7 +8,7 @@ - + diff --git a/src/MvvmScarletToolkit.Observables/MvvmScarletToolkit.Observables.csproj b/src/MvvmScarletToolkit.Observables/MvvmScarletToolkit.Observables.csproj index c059aa53..49f788d5 100644 --- a/src/MvvmScarletToolkit.Observables/MvvmScarletToolkit.Observables.csproj +++ b/src/MvvmScarletToolkit.Observables/MvvmScarletToolkit.Observables.csproj @@ -11,7 +11,7 @@ - + all From 439447065cd7cae0f281f53c1d4885d58b571470 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 31 May 2021 04:06:19 +0000 Subject: [PATCH 02/18] Bump Microsoft.NET.Test.Sdk from 16.9.4 to 16.10.0 Bumps [Microsoft.NET.Test.Sdk](https://github.com/microsoft/vstest) from 16.9.4 to 16.10.0. - [Release notes](https://github.com/microsoft/vstest/releases) - [Commits](https://github.com/microsoft/vstest/compare/v16.9.4...v16.10.0) Signed-off-by: dependabot[bot] --- .../MvvmScarletToolkit.Wpf.Tests.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MvvmScarletToolkit.Wpf.Tests/MvvmScarletToolkit.Wpf.Tests.csproj b/src/MvvmScarletToolkit.Wpf.Tests/MvvmScarletToolkit.Wpf.Tests.csproj index f41e2e49..c9415d31 100644 --- a/src/MvvmScarletToolkit.Wpf.Tests/MvvmScarletToolkit.Wpf.Tests.csproj +++ b/src/MvvmScarletToolkit.Wpf.Tests/MvvmScarletToolkit.Wpf.Tests.csproj @@ -16,7 +16,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + From 5ae06d00641dd9a54751f1945e4fa3e02c779137 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 14 Jun 2021 04:14:24 +0000 Subject: [PATCH 03/18] Bump NUnit3TestAdapter from 3.17.0 to 4.0.0 Bumps [NUnit3TestAdapter](https://github.com/nunit/nunit3-vs-adapter) from 3.17.0 to 4.0.0. - [Release notes](https://github.com/nunit/nunit3-vs-adapter/releases) - [Commits](https://github.com/nunit/nunit3-vs-adapter/compare/V3.17...V4.0.0) --- updated-dependencies: - dependency-name: NUnit3TestAdapter dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .../MvvmScarletToolkit.Wpf.Tests.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MvvmScarletToolkit.Wpf.Tests/MvvmScarletToolkit.Wpf.Tests.csproj b/src/MvvmScarletToolkit.Wpf.Tests/MvvmScarletToolkit.Wpf.Tests.csproj index f41e2e49..9e0f3b52 100644 --- a/src/MvvmScarletToolkit.Wpf.Tests/MvvmScarletToolkit.Wpf.Tests.csproj +++ b/src/MvvmScarletToolkit.Wpf.Tests/MvvmScarletToolkit.Wpf.Tests.csproj @@ -12,7 +12,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive From f29a09474afad1b421443ecaa490c1a496cddcdc Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 14 Jun 2021 04:14:32 +0000 Subject: [PATCH 04/18] Bump Roslynator.Analyzers from 3.1.0 to 3.2.0 Bumps [Roslynator.Analyzers](https://github.com/JosefPihrt/Roslynator) from 3.1.0 to 3.2.0. - [Release notes](https://github.com/JosefPihrt/Roslynator/releases) - [Changelog](https://github.com/JosefPihrt/Roslynator/blob/master/ChangeLog.md) - [Commits](https://github.com/JosefPihrt/Roslynator/compare/v3.1.0...v3.2.0) --- updated-dependencies: - dependency-name: Roslynator.Analyzers dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- .../MvvmScarletToolkit.Abstractions.csproj | 2 +- .../MvvmScarletToolkit.Commands.csproj | 2 +- .../MvvmScarletToolkit.Incubator.csproj | 2 +- .../MvvmScarletToolkit.Observables.csproj | 2 +- .../MvvmScarletToolkit.Wpf.Samples.csproj | 2 +- src/MvvmScarletToolkit.Wpf/MvvmScarletToolkit.Wpf.csproj | 2 +- .../MvvmScarletToolkit.Xamarin.Forms.csproj | 2 +- src/MvvmScarletToolkit/MvvmScarletToolkit.csproj | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/MvvmScarletToolkit.Abstractions/MvvmScarletToolkit.Abstractions.csproj b/src/MvvmScarletToolkit.Abstractions/MvvmScarletToolkit.Abstractions.csproj index 1613a7ef..fc1682c1 100644 --- a/src/MvvmScarletToolkit.Abstractions/MvvmScarletToolkit.Abstractions.csproj +++ b/src/MvvmScarletToolkit.Abstractions/MvvmScarletToolkit.Abstractions.csproj @@ -9,7 +9,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/src/MvvmScarletToolkit.Commands/MvvmScarletToolkit.Commands.csproj b/src/MvvmScarletToolkit.Commands/MvvmScarletToolkit.Commands.csproj index 7e2a2440..abae6d18 100644 --- a/src/MvvmScarletToolkit.Commands/MvvmScarletToolkit.Commands.csproj +++ b/src/MvvmScarletToolkit.Commands/MvvmScarletToolkit.Commands.csproj @@ -12,7 +12,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/src/MvvmScarletToolkit.Incubator/MvvmScarletToolkit.Incubator.csproj b/src/MvvmScarletToolkit.Incubator/MvvmScarletToolkit.Incubator.csproj index d9fba428..e3e2e91b 100644 --- a/src/MvvmScarletToolkit.Incubator/MvvmScarletToolkit.Incubator.csproj +++ b/src/MvvmScarletToolkit.Incubator/MvvmScarletToolkit.Incubator.csproj @@ -12,7 +12,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/src/MvvmScarletToolkit.Observables/MvvmScarletToolkit.Observables.csproj b/src/MvvmScarletToolkit.Observables/MvvmScarletToolkit.Observables.csproj index 49f788d5..d0a14c83 100644 --- a/src/MvvmScarletToolkit.Observables/MvvmScarletToolkit.Observables.csproj +++ b/src/MvvmScarletToolkit.Observables/MvvmScarletToolkit.Observables.csproj @@ -13,7 +13,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/src/MvvmScarletToolkit.Wpf.Samples/MvvmScarletToolkit.Wpf.Samples.csproj b/src/MvvmScarletToolkit.Wpf.Samples/MvvmScarletToolkit.Wpf.Samples.csproj index d1cea03b..472a7cb5 100644 --- a/src/MvvmScarletToolkit.Wpf.Samples/MvvmScarletToolkit.Wpf.Samples.csproj +++ b/src/MvvmScarletToolkit.Wpf.Samples/MvvmScarletToolkit.Wpf.Samples.csproj @@ -11,7 +11,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/src/MvvmScarletToolkit.Wpf/MvvmScarletToolkit.Wpf.csproj b/src/MvvmScarletToolkit.Wpf/MvvmScarletToolkit.Wpf.csproj index ecdfced0..e1a1ace7 100644 --- a/src/MvvmScarletToolkit.Wpf/MvvmScarletToolkit.Wpf.csproj +++ b/src/MvvmScarletToolkit.Wpf/MvvmScarletToolkit.Wpf.csproj @@ -13,7 +13,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/src/MvvmScarletToolkit.Xamarin.Forms/MvvmScarletToolkit.Xamarin.Forms.csproj b/src/MvvmScarletToolkit.Xamarin.Forms/MvvmScarletToolkit.Xamarin.Forms.csproj index 7e9f6e67..0f9967d4 100644 --- a/src/MvvmScarletToolkit.Xamarin.Forms/MvvmScarletToolkit.Xamarin.Forms.csproj +++ b/src/MvvmScarletToolkit.Xamarin.Forms/MvvmScarletToolkit.Xamarin.Forms.csproj @@ -12,7 +12,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/src/MvvmScarletToolkit/MvvmScarletToolkit.csproj b/src/MvvmScarletToolkit/MvvmScarletToolkit.csproj index 834e3e75..349b55c5 100644 --- a/src/MvvmScarletToolkit/MvvmScarletToolkit.csproj +++ b/src/MvvmScarletToolkit/MvvmScarletToolkit.csproj @@ -12,7 +12,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive From 54dcc38fc0fc89fbb95138b018f35c91dbfa55ea Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 28 Jun 2021 04:07:26 +0000 Subject: [PATCH 05/18] Bump Nerdbank.GitVersioning from 3.4.194 to 3.4.220 Bumps [Nerdbank.GitVersioning](https://github.com/dotnet/Nerdbank.GitVersioning) from 3.4.194 to 3.4.220. - [Release notes](https://github.com/dotnet/Nerdbank.GitVersioning/releases) - [Commits](https://github.com/dotnet/Nerdbank.GitVersioning/compare/v3.4.194...v3.4.220) --- updated-dependencies: - dependency-name: Nerdbank.GitVersioning dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- .../MvvmScarletToolkit.Abstractions.csproj | 2 +- .../MvvmScarletToolkit.Commands.csproj | 2 +- .../MvvmScarletToolkit.Observables.csproj | 2 +- src/MvvmScarletToolkit.Wpf/MvvmScarletToolkit.Wpf.csproj | 2 +- .../MvvmScarletToolkit.Xamarin.Forms.csproj | 2 +- src/MvvmScarletToolkit/MvvmScarletToolkit.csproj | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/MvvmScarletToolkit.Abstractions/MvvmScarletToolkit.Abstractions.csproj b/src/MvvmScarletToolkit.Abstractions/MvvmScarletToolkit.Abstractions.csproj index fc1682c1..312fc2a0 100644 --- a/src/MvvmScarletToolkit.Abstractions/MvvmScarletToolkit.Abstractions.csproj +++ b/src/MvvmScarletToolkit.Abstractions/MvvmScarletToolkit.Abstractions.csproj @@ -14,7 +14,7 @@ runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/src/MvvmScarletToolkit.Commands/MvvmScarletToolkit.Commands.csproj b/src/MvvmScarletToolkit.Commands/MvvmScarletToolkit.Commands.csproj index abae6d18..a3d82070 100644 --- a/src/MvvmScarletToolkit.Commands/MvvmScarletToolkit.Commands.csproj +++ b/src/MvvmScarletToolkit.Commands/MvvmScarletToolkit.Commands.csproj @@ -17,7 +17,7 @@ runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/src/MvvmScarletToolkit.Observables/MvvmScarletToolkit.Observables.csproj b/src/MvvmScarletToolkit.Observables/MvvmScarletToolkit.Observables.csproj index d0a14c83..adf41dc3 100644 --- a/src/MvvmScarletToolkit.Observables/MvvmScarletToolkit.Observables.csproj +++ b/src/MvvmScarletToolkit.Observables/MvvmScarletToolkit.Observables.csproj @@ -18,7 +18,7 @@ runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/src/MvvmScarletToolkit.Wpf/MvvmScarletToolkit.Wpf.csproj b/src/MvvmScarletToolkit.Wpf/MvvmScarletToolkit.Wpf.csproj index e1a1ace7..47d980cc 100644 --- a/src/MvvmScarletToolkit.Wpf/MvvmScarletToolkit.Wpf.csproj +++ b/src/MvvmScarletToolkit.Wpf/MvvmScarletToolkit.Wpf.csproj @@ -18,7 +18,7 @@ runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/src/MvvmScarletToolkit.Xamarin.Forms/MvvmScarletToolkit.Xamarin.Forms.csproj b/src/MvvmScarletToolkit.Xamarin.Forms/MvvmScarletToolkit.Xamarin.Forms.csproj index 0f9967d4..2e072d7e 100644 --- a/src/MvvmScarletToolkit.Xamarin.Forms/MvvmScarletToolkit.Xamarin.Forms.csproj +++ b/src/MvvmScarletToolkit.Xamarin.Forms/MvvmScarletToolkit.Xamarin.Forms.csproj @@ -17,7 +17,7 @@ runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/src/MvvmScarletToolkit/MvvmScarletToolkit.csproj b/src/MvvmScarletToolkit/MvvmScarletToolkit.csproj index 349b55c5..32d4ce1a 100644 --- a/src/MvvmScarletToolkit/MvvmScarletToolkit.csproj +++ b/src/MvvmScarletToolkit/MvvmScarletToolkit.csproj @@ -17,7 +17,7 @@ runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive From f35f5036118357dc7f7bbeea775e1d463bc3c441 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 28 Jun 2021 04:07:29 +0000 Subject: [PATCH 06/18] Bump XamlFlair.WPF from 1.2.8 to 1.2.9 Bumps [XamlFlair.WPF](https://github.com/XamlFlair/XamlFlair) from 1.2.8 to 1.2.9. - [Release notes](https://github.com/XamlFlair/XamlFlair/releases) - [Changelog](https://github.com/XamlFlair/XamlFlair/blob/master/build-release.bat) - [Commits](https://github.com/XamlFlair/XamlFlair/commits) --- updated-dependencies: - dependency-name: XamlFlair.WPF dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- .../MvvmScarletToolkit.Wpf.Samples.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MvvmScarletToolkit.Wpf.Samples/MvvmScarletToolkit.Wpf.Samples.csproj b/src/MvvmScarletToolkit.Wpf.Samples/MvvmScarletToolkit.Wpf.Samples.csproj index 472a7cb5..9fb538cd 100644 --- a/src/MvvmScarletToolkit.Wpf.Samples/MvvmScarletToolkit.Wpf.Samples.csproj +++ b/src/MvvmScarletToolkit.Wpf.Samples/MvvmScarletToolkit.Wpf.Samples.csproj @@ -16,7 +16,7 @@ runtime; build; native; contentfiles; analyzers; buildtransitive - + From cdb2c3689cf59dd1620942cddc967e5a84d944c0 Mon Sep 17 00:00:00 2001 From: Peter Vietense Date: Sat, 3 Jul 2021 12:37:33 +0200 Subject: [PATCH 07/18] added Batch extension method --- .../Extensions/EnumerableExtensions.cs | 35 ++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/src/MvvmScarletToolkit/Extensions/EnumerableExtensions.cs b/src/MvvmScarletToolkit/Extensions/EnumerableExtensions.cs index 67995812..7aab6e99 100644 --- a/src/MvvmScarletToolkit/Extensions/EnumerableExtensions.cs +++ b/src/MvvmScarletToolkit/Extensions/EnumerableExtensions.cs @@ -1,5 +1,4 @@ using System; -using System.Collections; using System.Collections.Concurrent; using System.Collections.Generic; using System.Linq; @@ -80,5 +79,39 @@ public static void AddRange(this ICollection source, IEnumerable items) { items.ForEach(p => source.Add(p)); } + + // source: https://stackoverflow.com/a/44505349 + public static IEnumerable> Batch(this IEnumerable source, int size) + { + if (size <= 0) + { + throw new ArgumentOutOfRangeException(nameof(size), "Must be greater than zero."); + } + + using (var enumerator = source.GetEnumerator()) + { + while (enumerator.MoveNext()) + { + var i = 0; + // Batch is a local function closing over `i` and `enumerator` that + // executes the inner batch enumeration + IEnumerable Batch() + { + do + { + yield return enumerator.Current; + } + while (++i < size && enumerator.MoveNext()); + } + + yield return Batch(); + + while (++i < size && enumerator.MoveNext()) + { + // discard skipped items + } + } + } + } } } From cd163c6c4d16d0c0f4859c840f1c0b84f46605c6 Mon Sep 17 00:00:00 2001 From: Peter Vietense Date: Sat, 3 Jul 2021 13:02:32 +0200 Subject: [PATCH 08/18] removed WeakEventManager since its now available from the Xamarin.Forms nuget package --- .../ScarletWeakEventManager.cs | 1 + .../Util/WeakEventManager.cs | 148 ------------------ 2 files changed, 1 insertion(+), 148 deletions(-) delete mode 100644 src/MvvmScarletToolkit.Xamarin.Forms/Util/WeakEventManager.cs diff --git a/src/MvvmScarletToolkit.Xamarin.Forms/Implementations/ScarletWeakEventManager.cs b/src/MvvmScarletToolkit.Xamarin.Forms/Implementations/ScarletWeakEventManager.cs index 62901b5f..1dc0f8c1 100644 --- a/src/MvvmScarletToolkit.Xamarin.Forms/Implementations/ScarletWeakEventManager.cs +++ b/src/MvvmScarletToolkit.Xamarin.Forms/Implementations/ScarletWeakEventManager.cs @@ -1,6 +1,7 @@ using MvvmScarletToolkit.Abstractions; using System; using System.ComponentModel; +using Xamarin.Forms; namespace MvvmScarletToolkit { diff --git a/src/MvvmScarletToolkit.Xamarin.Forms/Util/WeakEventManager.cs b/src/MvvmScarletToolkit.Xamarin.Forms/Util/WeakEventManager.cs deleted file mode 100644 index a50afccd..00000000 --- a/src/MvvmScarletToolkit.Xamarin.Forms/Util/WeakEventManager.cs +++ /dev/null @@ -1,148 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Reflection; -using System.Runtime.CompilerServices; - -namespace MvvmScarletToolkit -{ - // this is an almost verbatim copy of the xamarin.forms internal WeakeventManager, since its "internal" we cant just reuse it just yet - // there is an issue for that open already: https://github.com/xamarin/Xamarin.Forms/issues/8405 - internal sealed class WeakEventManager - { - private readonly Dictionary> _eventHandlers = new Dictionary>(); - - public void AddEventHandler(EventHandler handler, [CallerMemberName] string eventName = null!) - where TEventArgs : EventArgs - { - if (string.IsNullOrEmpty(eventName)) - throw new ArgumentNullException(nameof(eventName)); - - if (handler == null) - throw new ArgumentNullException(nameof(handler)); - - AddEventHandler(eventName, handler.Target, handler.GetMethodInfo()); - } - - public void AddEventHandler(EventHandler handler, [CallerMemberName] string eventName = null!) - { - if (string.IsNullOrEmpty(eventName)) - throw new ArgumentNullException(nameof(eventName)); - - if (handler == null) - throw new ArgumentNullException(nameof(handler)); - - AddEventHandler(eventName, handler.Target, handler.GetMethodInfo()); - } - - public void HandleEvent(object sender, object args, string eventName) - { - var toRaise = new List<(object? subscriber, MethodInfo handler)>(); - var toRemove = new List(); - - if (_eventHandlers.TryGetValue(eventName, out var target)) - { - for (var i = 0; i < target.Count; i++) - { - var subscription = target[i]; - var isStatic = subscription.Subscriber == null; - if (isStatic) - { - // For a static method, we'll just pass null as the first parameter of MethodInfo.Invoke - toRaise.Add((null, subscription.Handler)); - continue; - } - - var subscriber = subscription.Subscriber?.Target; - - if (subscriber == null) - // The subscriber was collected, so there's no need to keep this subscription around - toRemove.Add(subscription); - else - toRaise.Add((subscriber, subscription.Handler)); - } - - for (var i = 0; i < toRemove.Count; i++) - { - var subscription = toRemove[i]; - target.Remove(subscription); - } - } - - for (var i = 0; i < toRaise.Count; i++) - { - (var subscriber, var handler) = toRaise[i]; - handler.Invoke(subscriber, new[] { sender, args }); - } - } - - public void RemoveEventHandler(EventHandler handler, [CallerMemberName] string eventName = null!) - where TEventArgs : EventArgs - { - if (string.IsNullOrEmpty(eventName)) - throw new ArgumentNullException(nameof(eventName)); - - if (handler == null) - throw new ArgumentNullException(nameof(handler)); - - RemoveEventHandler(eventName, handler.Target, handler.GetMethodInfo()); - } - - public void RemoveEventHandler(EventHandler handler, [CallerMemberName] string eventName = null!) - { - if (string.IsNullOrEmpty(eventName)) - throw new ArgumentNullException(nameof(eventName)); - - if (handler == null) - throw new ArgumentNullException(nameof(handler)); - - RemoveEventHandler(eventName, handler.Target, handler.GetMethodInfo()); - } - - private void AddEventHandler(string eventName, object handlerTarget, MethodInfo methodInfo) - { - if (!_eventHandlers.TryGetValue(eventName, out var targets)) - { - targets = new List(); - _eventHandlers.Add(eventName, targets); - } - - if (handlerTarget == null) - { - // This event handler is a static method - targets.Add(new Subscription(default, methodInfo)); - return; - } - - targets.Add(new Subscription(new WeakReference(handlerTarget), methodInfo)); - } - - private void RemoveEventHandler(string eventName, object handlerTarget, MemberInfo methodInfo) - { - if (!_eventHandlers.TryGetValue(eventName, out var subscriptions)) - return; - - for (var n = subscriptions.Count; n > 0; n--) - { - var current = subscriptions[n - 1]; - - if (current.Subscriber?.Target != handlerTarget || current.Handler.Name != methodInfo.Name) - continue; - - subscriptions.Remove(current); - break; - } - } - - private struct Subscription - { - public readonly WeakReference? Subscriber; - public readonly MethodInfo Handler; - - public Subscription(WeakReference? subscriber, MethodInfo handler) - { - Subscriber = subscriber; - Handler = handler ?? throw new ArgumentNullException(nameof(handler)); - } - } - } -} From 3630c9ff3947dd11f6b4eff0e175a25b5423ba74 Mon Sep 17 00:00:00 2001 From: Peter Vietense Date: Sat, 3 Jul 2021 13:03:28 +0200 Subject: [PATCH 09/18] ported popular Converters from wpf to Xamarin.Forms --- .../ValueConverters/ConverterBase.cs | 16 ++++++++++++ .../ValueConverters/IsNot.cs | 25 +++++++++++++++++++ .../ValueConverters/IsNotNull.cs | 19 ++++++++++++++ .../ValueConverters/IsNotNullOrEmpty.cs | 25 +++++++++++++++++++ .../ValueConverters/IsNotNullOrWhiteSpace.cs | 25 +++++++++++++++++++ .../ValueConverters/IsNull.cs | 19 ++++++++++++++ .../ValueConverters/IsNullOrEmpty.cs | 25 +++++++++++++++++++ .../ValueConverters/IsNullOrWhiteSpace.cs | 25 +++++++++++++++++++ 8 files changed, 179 insertions(+) create mode 100644 src/MvvmScarletToolkit.Xamarin.Forms/ValueConverters/ConverterBase.cs create mode 100644 src/MvvmScarletToolkit.Xamarin.Forms/ValueConverters/IsNot.cs create mode 100644 src/MvvmScarletToolkit.Xamarin.Forms/ValueConverters/IsNotNull.cs create mode 100644 src/MvvmScarletToolkit.Xamarin.Forms/ValueConverters/IsNotNullOrEmpty.cs create mode 100644 src/MvvmScarletToolkit.Xamarin.Forms/ValueConverters/IsNotNullOrWhiteSpace.cs create mode 100644 src/MvvmScarletToolkit.Xamarin.Forms/ValueConverters/IsNull.cs create mode 100644 src/MvvmScarletToolkit.Xamarin.Forms/ValueConverters/IsNullOrEmpty.cs create mode 100644 src/MvvmScarletToolkit.Xamarin.Forms/ValueConverters/IsNullOrWhiteSpace.cs diff --git a/src/MvvmScarletToolkit.Xamarin.Forms/ValueConverters/ConverterBase.cs b/src/MvvmScarletToolkit.Xamarin.Forms/ValueConverters/ConverterBase.cs new file mode 100644 index 00000000..8710946d --- /dev/null +++ b/src/MvvmScarletToolkit.Xamarin.Forms/ValueConverters/ConverterBase.cs @@ -0,0 +1,16 @@ +using System; +using System.Globalization; +using Xamarin.Forms; + +namespace MvvmScarletToolkit +{ + public abstract class ConverterBase : IValueConverter + { + public abstract object Convert(object value, Type targetType, object parameter, CultureInfo culture); + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + return Binding.DoNothing; + } + } +} diff --git a/src/MvvmScarletToolkit.Xamarin.Forms/ValueConverters/IsNot.cs b/src/MvvmScarletToolkit.Xamarin.Forms/ValueConverters/IsNot.cs new file mode 100644 index 00000000..88ad5d32 --- /dev/null +++ b/src/MvvmScarletToolkit.Xamarin.Forms/ValueConverters/IsNot.cs @@ -0,0 +1,25 @@ +using System; +using System.Globalization; +using Xamarin.Forms; + +namespace MvvmScarletToolkit +{ + /// + /// negate a boolean value + /// + /// + /// xmlns:mvvm="http://SoftThorn.MvvmScarletToolkit.com/winfx/xaml/shared" + /// + public sealed class IsNot : ConverterBase + { + public override object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + if (value is bool boolean) + { + return !boolean; + } + + return Binding.DoNothing; + } + } +} diff --git a/src/MvvmScarletToolkit.Xamarin.Forms/ValueConverters/IsNotNull.cs b/src/MvvmScarletToolkit.Xamarin.Forms/ValueConverters/IsNotNull.cs new file mode 100644 index 00000000..358237b0 --- /dev/null +++ b/src/MvvmScarletToolkit.Xamarin.Forms/ValueConverters/IsNotNull.cs @@ -0,0 +1,19 @@ +using System; +using System.Globalization; + +namespace MvvmScarletToolkit +{ + /// + /// whether something is not null + /// + /// + /// xmlns:mvvm="http://SoftThorn.MvvmScarletToolkit.com/winfx/xaml/shared" + /// + public sealed class IsNotNull : ConverterBase + { + public override object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + return !(value is null); + } + } +} diff --git a/src/MvvmScarletToolkit.Xamarin.Forms/ValueConverters/IsNotNullOrEmpty.cs b/src/MvvmScarletToolkit.Xamarin.Forms/ValueConverters/IsNotNullOrEmpty.cs new file mode 100644 index 00000000..1c1336f9 --- /dev/null +++ b/src/MvvmScarletToolkit.Xamarin.Forms/ValueConverters/IsNotNullOrEmpty.cs @@ -0,0 +1,25 @@ +using System; +using System.Globalization; +using Xamarin.Forms; + +namespace MvvmScarletToolkit +{ + /// + /// whether a string is not null or empty + /// + /// + /// xmlns:mvvm="http://SoftThorn.MvvmScarletToolkit.com/winfx/xaml/shared" + /// + public sealed class IsNotNullOrEmpty : ConverterBase + { + public override object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + if (value is string text) + { + return !string.IsNullOrEmpty(text); + } + + return Binding.DoNothing; + } + } +} diff --git a/src/MvvmScarletToolkit.Xamarin.Forms/ValueConverters/IsNotNullOrWhiteSpace.cs b/src/MvvmScarletToolkit.Xamarin.Forms/ValueConverters/IsNotNullOrWhiteSpace.cs new file mode 100644 index 00000000..e4b52957 --- /dev/null +++ b/src/MvvmScarletToolkit.Xamarin.Forms/ValueConverters/IsNotNullOrWhiteSpace.cs @@ -0,0 +1,25 @@ +using System; +using System.Globalization; +using Xamarin.Forms; + +namespace MvvmScarletToolkit +{ + /// + /// whether a string is not null or whitespace + /// + /// + /// xmlns:mvvm="http://SoftThorn.MvvmScarletToolkit.com/winfx/xaml/shared" + /// + public sealed class IsNotNullOrWhiteSpace : ConverterBase + { + public override object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + if (value is string text) + { + return !string.IsNullOrWhiteSpace(text); + } + + return Binding.DoNothing; + } + } +} diff --git a/src/MvvmScarletToolkit.Xamarin.Forms/ValueConverters/IsNull.cs b/src/MvvmScarletToolkit.Xamarin.Forms/ValueConverters/IsNull.cs new file mode 100644 index 00000000..83562400 --- /dev/null +++ b/src/MvvmScarletToolkit.Xamarin.Forms/ValueConverters/IsNull.cs @@ -0,0 +1,19 @@ +using System; +using System.Globalization; + +namespace MvvmScarletToolkit +{ + /// + /// whether something is null + /// + /// + /// xmlns:mvvm="http://SoftThorn.MvvmScarletToolkit.com/winfx/xaml/shared" + /// + public sealed class IsNull : ConverterBase + { + public override object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + return value is null; + } + } +} diff --git a/src/MvvmScarletToolkit.Xamarin.Forms/ValueConverters/IsNullOrEmpty.cs b/src/MvvmScarletToolkit.Xamarin.Forms/ValueConverters/IsNullOrEmpty.cs new file mode 100644 index 00000000..a1bb62c6 --- /dev/null +++ b/src/MvvmScarletToolkit.Xamarin.Forms/ValueConverters/IsNullOrEmpty.cs @@ -0,0 +1,25 @@ +using System; +using System.Globalization; +using Xamarin.Forms; + +namespace MvvmScarletToolkit +{ + /// + /// whether a string is null or empty + /// + /// + /// xmlns:mvvm="http://SoftThorn.MvvmScarletToolkit.com/winfx/xaml/shared" + /// + public sealed class IsNullOrEmpty : ConverterBase + { + public override object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + if (value is string text) + { + return string.IsNullOrEmpty(text); + } + + return Binding.DoNothing; + } + } +} diff --git a/src/MvvmScarletToolkit.Xamarin.Forms/ValueConverters/IsNullOrWhiteSpace.cs b/src/MvvmScarletToolkit.Xamarin.Forms/ValueConverters/IsNullOrWhiteSpace.cs new file mode 100644 index 00000000..102c9e30 --- /dev/null +++ b/src/MvvmScarletToolkit.Xamarin.Forms/ValueConverters/IsNullOrWhiteSpace.cs @@ -0,0 +1,25 @@ +using System; +using System.Globalization; +using Xamarin.Forms; + +namespace MvvmScarletToolkit +{ + /// + /// whether a string is null or whitespace + /// + /// + /// xmlns:mvvm="http://SoftThorn.MvvmScarletToolkit.com/winfx/xaml/shared" + /// + public sealed class IsNullOrWhiteSpace : ConverterBase + { + public override object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + if (value is string text) + { + return string.IsNullOrWhiteSpace(text); + } + + return Binding.DoNothing; + } + } +} From 2a429592ae3bb43efa158c21fba6cbd8ee5c66fa Mon Sep 17 00:00:00 2001 From: Peter Vietense Date: Sat, 3 Jul 2021 13:03:50 +0200 Subject: [PATCH 10/18] removed InvertBooleanConverter as it is now being covered by the IsNot Converter --- .../ValueConverters/InvertBooleanConverter.cs | 19 ------------------- 1 file changed, 19 deletions(-) delete mode 100644 src/MvvmScarletToolkit.Xamarin.Forms/ValueConverters/InvertBooleanConverter.cs diff --git a/src/MvvmScarletToolkit.Xamarin.Forms/ValueConverters/InvertBooleanConverter.cs b/src/MvvmScarletToolkit.Xamarin.Forms/ValueConverters/InvertBooleanConverter.cs deleted file mode 100644 index 3236b207..00000000 --- a/src/MvvmScarletToolkit.Xamarin.Forms/ValueConverters/InvertBooleanConverter.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System; -using System.Globalization; -using Xamarin.Forms; - -namespace MvvmScarletToolkit -{ - public sealed class InvertBooleanConverter : IValueConverter - { - public object Convert(object value, Type targetType, object parameter, CultureInfo culture) - { - return !(bool)value; - } - - public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) - { - return value; - } - } -} From b47b858aa10e01bf256824cbfd6cd02530c88ed2 Mon Sep 17 00:00:00 2001 From: Peter Vietense Date: Sat, 3 Jul 2021 13:20:21 +0200 Subject: [PATCH 11/18] added namespace mappings to Xamarin.Forms project --- .../Properties/AssemblyInfo.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/MvvmScarletToolkit.Xamarin.Forms/Properties/AssemblyInfo.cs b/src/MvvmScarletToolkit.Xamarin.Forms/Properties/AssemblyInfo.cs index 6bd47fe2..4493b877 100644 --- a/src/MvvmScarletToolkit.Xamarin.Forms/Properties/AssemblyInfo.cs +++ b/src/MvvmScarletToolkit.Xamarin.Forms/Properties/AssemblyInfo.cs @@ -1,5 +1,7 @@ using System.Reflection; using System.Runtime.InteropServices; +using Xamarin.Forms; +using Xamarin.Forms.Internals; // General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information @@ -16,3 +18,6 @@ // The following GUID is for the ID of the typelib if this project is exposed to COM [assembly: Guid("9bd9b759-8c12-4e08-971b-9ba21d8247ff")] +[assembly: Preserve(AllMembers = true)] +[assembly: XmlnsPrefix("http://SoftThorn.MvvmScarletToolkit.com/winfx/xaml/shared", "mvvm")] +[assembly: XmlnsDefinition("http://SoftThorn.MvvmScarletToolkit.com/winfx/xaml/shared", "MvvmScarletToolkit")] From 44f6ad2e623825bac6073e8a3598714c5306bd56 Mon Sep 17 00:00:00 2001 From: Peter Vietense Date: Sat, 3 Jul 2021 13:20:39 +0200 Subject: [PATCH 12/18] housekeeping --- .../ToastNotification/ToastService.cs | 2 +- .../MarkupExtensions/ColorToHexExtension.cs | 6 ++-- .../Extensions/EnumerableExtensions.cs | 33 +++++++++++-------- 3 files changed, 22 insertions(+), 19 deletions(-) diff --git a/src/MvvmScarletToolkit.Wpf/Features/ToastNotification/ToastService.cs b/src/MvvmScarletToolkit.Wpf/Features/ToastNotification/ToastService.cs index b144d474..9d1654f8 100644 --- a/src/MvvmScarletToolkit.Wpf/Features/ToastNotification/ToastService.cs +++ b/src/MvvmScarletToolkit.Wpf/Features/ToastNotification/ToastService.cs @@ -14,7 +14,7 @@ namespace MvvmScarletToolkit.Wpf { public class ToastService : ObservableObject, IToastService { - private static readonly Lazy _default = new Lazy(() => new ToastService(new ToastServiceConfiguration(), SynchronizationContext.Current)); + private static readonly Lazy _default = new Lazy(() => new ToastService(new ToastServiceConfiguration(), SynchronizationContext.Current!)); public static IToastService Default => _default.Value; diff --git a/src/MvvmScarletToolkit.Xamarin.Forms/MarkupExtensions/ColorToHexExtension.cs b/src/MvvmScarletToolkit.Xamarin.Forms/MarkupExtensions/ColorToHexExtension.cs index 1a5da38c..2418389c 100644 --- a/src/MvvmScarletToolkit.Xamarin.Forms/MarkupExtensions/ColorToHexExtension.cs +++ b/src/MvvmScarletToolkit.Xamarin.Forms/MarkupExtensions/ColorToHexExtension.cs @@ -7,16 +7,14 @@ namespace MvvmScarletToolkit { [Preserve(AllMembers = true)] [ContentProperty(nameof(Color))] - [System.Diagnostics.CodeAnalysis.SuppressMessage("PropertyChangedAnalyzers.PropertyChanged", "INPC001:The class has mutable properties and should implement INotifyPropertyChanged.", Justification = "One does not bind to markupextensions, they are the target for value setting, not the source of value generation")] + [AcceptEmptyServiceProvider] public sealed class ColorToHexExtension : IMarkupExtension { public Color Color { get; set; } public object ProvideValue(IServiceProvider serviceProvider) { - var hex = Color.ToHex(); - - return hex; + return Color.ToHex(); } } } diff --git a/src/MvvmScarletToolkit/Extensions/EnumerableExtensions.cs b/src/MvvmScarletToolkit/Extensions/EnumerableExtensions.cs index 7aab6e99..c9dbcabc 100644 --- a/src/MvvmScarletToolkit/Extensions/EnumerableExtensions.cs +++ b/src/MvvmScarletToolkit/Extensions/EnumerableExtensions.cs @@ -88,27 +88,32 @@ public static IEnumerable> Batch(this IEnumerable< throw new ArgumentOutOfRangeException(nameof(size), "Must be greater than zero."); } - using (var enumerator = source.GetEnumerator()) + return BatchInternal(); + + IEnumerable> BatchInternal() { - while (enumerator.MoveNext()) + using (var enumerator = source.GetEnumerator()) { - var i = 0; - // Batch is a local function closing over `i` and `enumerator` that - // executes the inner batch enumeration - IEnumerable Batch() + while (enumerator.MoveNext()) { - do + var i = 0; + // Batch is a local function closing over `i` and `enumerator` that + // executes the inner batch enumeration + IEnumerable Batch() { - yield return enumerator.Current; + do + { + yield return enumerator.Current; + } + while (++i < size && enumerator.MoveNext()); } - while (++i < size && enumerator.MoveNext()); - } - yield return Batch(); + yield return Batch(); - while (++i < size && enumerator.MoveNext()) - { - // discard skipped items + while (++i < size && enumerator.MoveNext()) + { + // discard skipped items + } } } } From ed148f2702403a97ae1294cd60bf05d1d2b4cb15 Mon Sep 17 00:00:00 2001 From: Peter Vietense Date: Sat, 3 Jul 2021 13:22:12 +0200 Subject: [PATCH 13/18] updated Xamarin.Forms sample to showcase usage of commands and converters --- .../MainPage.xaml | 23 ++++++++++++++----- .../MainPageViewModel.cs | 11 ++++++--- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/src/MvvmScarletToolkit.Xamarin.Forms.Samples/MainPage.xaml b/src/MvvmScarletToolkit.Xamarin.Forms.Samples/MainPage.xaml index b7a5f0cc..19edd193 100644 --- a/src/MvvmScarletToolkit.Xamarin.Forms.Samples/MainPage.xaml +++ b/src/MvvmScarletToolkit.Xamarin.Forms.Samples/MainPage.xaml @@ -2,23 +2,34 @@ + + + + - + +