From bbfdb6d3ab7717a55c6cf1dfdaf2967a990b5d7b Mon Sep 17 00:00:00 2001 From: David Vreony Date: Sun, 9 Jun 2024 15:12:29 +0100 Subject: [PATCH] simplify command binding generics --- .../QuestionnaireViewBindingModels.cs | 1 + src/Vetuviem.Core/CommandBinding.cs | 11 +++++------ src/Vetuviem.Core/ICommandBinding.cs | 9 +++++---- .../ControlBindingModelPropertyGenerator.cs | 2 +- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/ReactiveUI.WPF.SampleApp/ViewBindingModels/QuestionnaireViewBindingModels.cs b/src/ReactiveUI.WPF.SampleApp/ViewBindingModels/QuestionnaireViewBindingModels.cs index 41c7cfe..e273995 100644 --- a/src/ReactiveUI.WPF.SampleApp/ViewBindingModels/QuestionnaireViewBindingModels.cs +++ b/src/ReactiveUI.WPF.SampleApp/ViewBindingModels/QuestionnaireViewBindingModels.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using System.Linq.Expressions; using System.Windows.Controls; +using System.Windows.Input; using System.Windows.Media; using ReactiveUI.WPF.SampleApp.ViewModels; using ReactiveUI.WPF.SampleApp.Views; diff --git a/src/Vetuviem.Core/CommandBinding.cs b/src/Vetuviem.Core/CommandBinding.cs index 1b65bb0..c6f1129 100644 --- a/src/Vetuviem.Core/CommandBinding.cs +++ b/src/Vetuviem.Core/CommandBinding.cs @@ -4,7 +4,6 @@ using System; using System.Linq.Expressions; -using System.Reactive; using System.Reactive.Disposables; using System.Windows.Input; using ReactiveUI; @@ -15,7 +14,7 @@ namespace Vetuviem.Core /// Represents a command binding between a control and a viewmodel. /// /// The type for the viewmodel. - public sealed class CommandBinding : ICommandBinding + public sealed class CommandBinding : ICommandBinding where TViewModel : class { private readonly Expression> _viewModelBinding; @@ -35,11 +34,11 @@ public CommandBinding( } /// - public void ApplyBinding( + public void ApplyBinding( Action disposeAction, TView view, TViewModel viewModel, - Expression> viewBinding) + Expression> viewBinding) where TView : class, IViewFor { if (disposeAction == null) @@ -70,11 +69,11 @@ public void ApplyBinding( } /// - public void ApplyBinding( + public void ApplyBinding( CompositeDisposable compositeDisposable, TView view, TViewModel viewModel, - Expression> viewBinding) + Expression> viewBinding) where TView : class, IViewFor { if (compositeDisposable == null) diff --git a/src/Vetuviem.Core/ICommandBinding.cs b/src/Vetuviem.Core/ICommandBinding.cs index 2a94e09..18c5b54 100644 --- a/src/Vetuviem.Core/ICommandBinding.cs +++ b/src/Vetuviem.Core/ICommandBinding.cs @@ -13,19 +13,19 @@ namespace Vetuviem.Core /// Represents a View to View Model Binding for Commands. /// /// The type for the ViewModel. - /// The type for the View. - public interface ICommandBinding + public interface ICommandBinding where TViewModel : class { /// /// Applies a View to View Model Binding. /// /// The type for the view. + /// The type for the View Property. /// The disposable action registration. Used to clean up when bindings fall out of scope. /// The instance of the View to bind. /// The instance of the ViewModel to Bind. /// Expression of the View Property to Bind to. - void ApplyBinding( + void ApplyBinding( Action d, TView view, TViewModel viewModel, @@ -36,11 +36,12 @@ void ApplyBinding( /// Applies a View to View Model Binding. /// /// The type for the view. + /// The type for the View Property. /// The disposable action registration. Used to clean up when bindings fall out of scope. /// The instance of the View to bind. /// The instance of the ViewModel to Bind. /// Expression of the View Property to Bind to. - void ApplyBinding( + void ApplyBinding( CompositeDisposable compositeDisposable, TView view, TViewModel viewModel, diff --git a/src/Vetuviem.SourceGenerator/Features/ControlBindingModels/ControlBindingModelPropertyGenerator.cs b/src/Vetuviem.SourceGenerator/Features/ControlBindingModels/ControlBindingModelPropertyGenerator.cs index 762d3ca..0db84d2 100644 --- a/src/Vetuviem.SourceGenerator/Features/ControlBindingModels/ControlBindingModelPropertyGenerator.cs +++ b/src/Vetuviem.SourceGenerator/Features/ControlBindingModels/ControlBindingModelPropertyGenerator.cs @@ -205,7 +205,7 @@ private static PropertyDeclarationSyntax GetPropertyDeclaration( private static TypeSyntax GetCommandBindingTypeSyntax(string platformCommandType) { - var type = SyntaxFactory.ParseTypeName($"global::Vetuviem.Core.ICommandBinding?"); + var type = SyntaxFactory.ParseTypeName($"global::Vetuviem.Core.ICommandBinding?"); return type; }