Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

breaking change: Make Bind use non-generic IViewFor #3677

Merged
merged 7 commits into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("ReactiveUI.AndroidSupport")]
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("ReactiveUI.Tests")]
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("ReactiveUI.Winforms")]
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("ReactiveUI.Wpf")]
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("ReactiveUI.XamForms")]
[assembly: System.Runtime.Versioning.TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName=".NET 6.0")]
namespace ReactiveUI.Fody.Helpers
{
[System.AttributeUsage(System.AttributeTargets.Method | System.AttributeTargets.Property)]
public sealed class ObservableAsPropertyAttribute : System.Attribute
{
public ObservableAsPropertyAttribute() { }
}
public static class ObservableAsPropertyExtensions
{
public static ReactiveUI.ObservableAsPropertyHelper<TRet> ToPropertyEx<TObj, TRet>(this System.IObservable<TRet> item, TObj source, System.Linq.Expressions.Expression<System.Func<TObj, TRet>> property, bool deferSubscription = false, System.Reactive.Concurrency.IScheduler? scheduler = null)
where TObj : ReactiveUI.ReactiveObject { }
public static ReactiveUI.ObservableAsPropertyHelper<TRet> ToPropertyEx<TObj, TRet>(this System.IObservable<TRet> item, TObj source, System.Linq.Expressions.Expression<System.Func<TObj, TRet>> property, TRet initialValue, bool deferSubscription = false, System.Reactive.Concurrency.IScheduler? scheduler = null)
where TObj : ReactiveUI.ReactiveObject { }
}
[System.AttributeUsage(System.AttributeTargets.Property)]
public sealed class ReactiveAttribute : System.Attribute
{
public ReactiveAttribute() { }
}
[System.AttributeUsage(System.AttributeTargets.Property)]
public sealed class ReactiveDependencyAttribute : System.Attribute
{
public ReactiveDependencyAttribute(string targetName) { }
public string Target { get; }
public string? TargetProperty { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("ReactiveUI.AndroidSupport")]
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("ReactiveUI.Tests")]
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("ReactiveUI.Winforms")]
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("ReactiveUI.Wpf")]
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("ReactiveUI.XamForms")]
[assembly: System.Runtime.Versioning.TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName=".NET Framework 4.7.2")]
namespace ReactiveUI.Fody.Helpers
{
[System.AttributeUsage(System.AttributeTargets.Method | System.AttributeTargets.Property)]
public sealed class ObservableAsPropertyAttribute : System.Attribute
{
public ObservableAsPropertyAttribute() { }
}
public static class ObservableAsPropertyExtensions
{
public static ReactiveUI.ObservableAsPropertyHelper<TRet> ToPropertyEx<TObj, TRet>(this System.IObservable<TRet> item, TObj source, System.Linq.Expressions.Expression<System.Func<TObj, TRet>> property, bool deferSubscription = false, System.Reactive.Concurrency.IScheduler? scheduler = null)
where TObj : ReactiveUI.ReactiveObject { }
public static ReactiveUI.ObservableAsPropertyHelper<TRet> ToPropertyEx<TObj, TRet>(this System.IObservable<TRet> item, TObj source, System.Linq.Expressions.Expression<System.Func<TObj, TRet>> property, TRet initialValue, bool deferSubscription = false, System.Reactive.Concurrency.IScheduler? scheduler = null)
where TObj : ReactiveUI.ReactiveObject { }
}
[System.AttributeUsage(System.AttributeTargets.Property)]
public sealed class ReactiveAttribute : System.Attribute
{
public ReactiveAttribute() { }
}
[System.AttributeUsage(System.AttributeTargets.Property)]
public sealed class ReactiveDependencyAttribute : System.Attribute
{
public ReactiveDependencyAttribute(string targetName) { }
public string Target { get; }
public string? TargetProperty { get; set; }
}
}
13 changes: 8 additions & 5 deletions src/ReactiveUI.Fody.Tests/API/ApiApprovalTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
// See the LICENSE file in the project root for full license information.

using System.Diagnostics.CodeAnalysis;

using System.Threading.Tasks;
using ReactiveUI.Fody.Helpers;

using ReactiveUI.Tests;
using VerifyXunit;
using Xunit;

namespace ReactiveUI.Fody.Tests.API;
Expand All @@ -18,11 +19,13 @@ namespace ReactiveUI.Fody.Tests.API;
/// for version changing reasons.
/// </summary>
[ExcludeFromCodeCoverage]
public class ApiApprovalTests : ApiApprovalBase
[UsesVerify]
public class ApiApprovalTests
{
/// <summary>
/// Checks the version API.
/// </summary>
/// <returns>A task to monitor the process.</returns>
[Fact]
public void ReactiveUIFody() => CheckApproval(typeof(ReactiveAttribute).Assembly);
}
public Task ReactiveUIFody() => typeof(ReactiveAttribute).Assembly.CheckApproval(["ReactiveUI"]);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,40 +8,32 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;

using PublicApiGenerator;

using VerifyTests;

using VerifyXunit;

namespace ReactiveUI.Tests;

/// <summary>
/// Tests for API approvals.
/// A helper for doing API approvals.
/// </summary>
[ExcludeFromCodeCoverage]
#pragma warning disable CA1050 // Declare types in namespaces
#pragma warning disable RCS1110 // Declare type inside namespace.
public abstract class ApiApprovalBase
#pragma warning restore RCS1110 // Declare type inside namespace.
#pragma warning restore CA1050 // Declare types in namespaces
[UsesVerify]
public static class ApiExtensions
{
/// <summary>
/// Checks the assembly to detect the public API. Generates a received/approved version of the API.
/// Checks to make sure the API is approved.
/// </summary>
/// <param name="assembly">The assembly to check.</param>
/// <param name="filePath">Auto populated file path.</param>
/// <returns>A task to monitor the progress.</returns>
protected static Task CheckApproval(Assembly assembly, [CallerFilePath]string? filePath = null)
/// <param name="assembly">The assembly that is being checked.</param>
/// <param name="namespaces">The namespaces.</param>
/// <param name="filePath">The caller file path.</param>
/// <returns>
/// A Task.
/// </returns>
public static async Task CheckApproval(this Assembly assembly, string[] namespaces, [CallerFilePath] string filePath = "")
{
if (filePath is null)
{
return Task.CompletedTask;
}

var generatorOptions = new ApiGeneratorOptions { AllowNamespacePrefixes = ["ReactiveUI"] };
var generatorOptions = new ApiGeneratorOptions { AllowNamespacePrefixes = namespaces };
var apiText = assembly.GeneratePublicApi(generatorOptions);
var verifySettings = new VerifySettings();
return Verifier.Verify(apiText, verifySettings, filePath)
var result = await Verifier.Verify(apiText, null, filePath)
.UniqueForRuntimeAndVersion()
.ScrubEmptyLines()
.ScrubLines(l =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,27 +81,27 @@ namespace ReactiveUI
public static class CommandBinder
{
public static ReactiveUI.IReactiveBinding<TView, TProp> BindCommand<TView, TViewModel, TProp, TControl>(this TView view, TViewModel? viewModel, System.Linq.Expressions.Expression<System.Func<TViewModel, TProp?>> propertyName, System.Linq.Expressions.Expression<System.Func<TView, TControl>> controlName, string? toEvent = null)
where TView : class, ReactiveUI.IViewFor<TViewModel>
where TView : class, ReactiveUI.IViewFor
where TViewModel : class
where TProp : System.Windows.Input.ICommand { }
public static ReactiveUI.IReactiveBinding<TView, TProp> BindCommand<TView, TViewModel, TProp, TControl, TParam>(this TView view, TViewModel? viewModel, System.Linq.Expressions.Expression<System.Func<TViewModel, TProp?>> propertyName, System.Linq.Expressions.Expression<System.Func<TView, TControl>> controlName, System.IObservable<TParam?> withParameter, string? toEvent = null)
where TView : class, ReactiveUI.IViewFor<TViewModel>
where TView : class, ReactiveUI.IViewFor
where TViewModel : class
where TProp : System.Windows.Input.ICommand { }
public static ReactiveUI.IReactiveBinding<TView, TProp> BindCommand<TView, TViewModel, TProp, TControl, TParam>(this TView view, TViewModel? viewModel, System.Linq.Expressions.Expression<System.Func<TViewModel, TProp?>> propertyName, System.Linq.Expressions.Expression<System.Func<TView, TControl>> controlName, System.Linq.Expressions.Expression<System.Func<TViewModel, TParam?>> withParameter, string? toEvent = null)
where TView : class, ReactiveUI.IViewFor<TViewModel>
where TView : class, ReactiveUI.IViewFor
where TViewModel : class
where TProp : System.Windows.Input.ICommand { }
}
public class CommandBinderImplementation : Splat.IEnableLogger
{
public CommandBinderImplementation() { }
public ReactiveUI.IReactiveBinding<TView, TProp> BindCommand<TView, TViewModel, TProp, TControl, TParam>(TViewModel? viewModel, TView view, System.Linq.Expressions.Expression<System.Func<TViewModel, TProp?>> vmProperty, System.Linq.Expressions.Expression<System.Func<TView, TControl>> controlProperty, System.IObservable<TParam?> withParameter, string? toEvent = null)
where TView : class, ReactiveUI.IViewFor<TViewModel>
where TView : class, ReactiveUI.IViewFor
where TViewModel : class
where TProp : System.Windows.Input.ICommand { }
public ReactiveUI.IReactiveBinding<TView, TProp> BindCommand<TView, TViewModel, TProp, TControl, TParam>(TViewModel? viewModel, TView view, System.Linq.Expressions.Expression<System.Func<TViewModel, TProp?>> vmProperty, System.Linq.Expressions.Expression<System.Func<TView, TControl>> controlProperty, System.Linq.Expressions.Expression<System.Func<TViewModel, TParam?>> withParameter, string? toEvent = null)
where TView : class, ReactiveUI.IViewFor<TViewModel>
where TView : class, ReactiveUI.IViewFor
where TViewModel : class
where TProp : System.Windows.Input.ICommand { }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,27 +81,27 @@ namespace ReactiveUI
public static class CommandBinder
{
public static ReactiveUI.IReactiveBinding<TView, TProp> BindCommand<TView, TViewModel, TProp, TControl>(this TView view, TViewModel? viewModel, System.Linq.Expressions.Expression<System.Func<TViewModel, TProp?>> propertyName, System.Linq.Expressions.Expression<System.Func<TView, TControl>> controlName, string? toEvent = null)
where TView : class, ReactiveUI.IViewFor<TViewModel>
where TView : class, ReactiveUI.IViewFor
where TViewModel : class
where TProp : System.Windows.Input.ICommand { }
public static ReactiveUI.IReactiveBinding<TView, TProp> BindCommand<TView, TViewModel, TProp, TControl, TParam>(this TView view, TViewModel? viewModel, System.Linq.Expressions.Expression<System.Func<TViewModel, TProp?>> propertyName, System.Linq.Expressions.Expression<System.Func<TView, TControl>> controlName, System.IObservable<TParam?> withParameter, string? toEvent = null)
where TView : class, ReactiveUI.IViewFor<TViewModel>
where TView : class, ReactiveUI.IViewFor
where TViewModel : class
where TProp : System.Windows.Input.ICommand { }
public static ReactiveUI.IReactiveBinding<TView, TProp> BindCommand<TView, TViewModel, TProp, TControl, TParam>(this TView view, TViewModel? viewModel, System.Linq.Expressions.Expression<System.Func<TViewModel, TProp?>> propertyName, System.Linq.Expressions.Expression<System.Func<TView, TControl>> controlName, System.Linq.Expressions.Expression<System.Func<TViewModel, TParam?>> withParameter, string? toEvent = null)
where TView : class, ReactiveUI.IViewFor<TViewModel>
where TView : class, ReactiveUI.IViewFor
where TViewModel : class
where TProp : System.Windows.Input.ICommand { }
}
public class CommandBinderImplementation : Splat.IEnableLogger
{
public CommandBinderImplementation() { }
public ReactiveUI.IReactiveBinding<TView, TProp> BindCommand<TView, TViewModel, TProp, TControl, TParam>(TViewModel? viewModel, TView view, System.Linq.Expressions.Expression<System.Func<TViewModel, TProp?>> vmProperty, System.Linq.Expressions.Expression<System.Func<TView, TControl>> controlProperty, System.IObservable<TParam?> withParameter, string? toEvent = null)
where TView : class, ReactiveUI.IViewFor<TViewModel>
where TView : class, ReactiveUI.IViewFor
where TViewModel : class
where TProp : System.Windows.Input.ICommand { }
public ReactiveUI.IReactiveBinding<TView, TProp> BindCommand<TView, TViewModel, TProp, TControl, TParam>(TViewModel? viewModel, TView view, System.Linq.Expressions.Expression<System.Func<TViewModel, TProp?>> vmProperty, System.Linq.Expressions.Expression<System.Func<TView, TControl>> controlProperty, System.Linq.Expressions.Expression<System.Func<TViewModel, TParam?>> withParameter, string? toEvent = null)
where TView : class, ReactiveUI.IViewFor<TViewModel>
where TView : class, ReactiveUI.IViewFor
where TViewModel : class
where TProp : System.Windows.Input.ICommand { }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,27 +81,27 @@ namespace ReactiveUI
public static class CommandBinder
{
public static ReactiveUI.IReactiveBinding<TView, TProp> BindCommand<TView, TViewModel, TProp, TControl>(this TView view, TViewModel? viewModel, System.Linq.Expressions.Expression<System.Func<TViewModel, TProp?>> propertyName, System.Linq.Expressions.Expression<System.Func<TView, TControl>> controlName, string? toEvent = null)
where TView : class, ReactiveUI.IViewFor<TViewModel>
where TView : class, ReactiveUI.IViewFor
where TViewModel : class
where TProp : System.Windows.Input.ICommand { }
public static ReactiveUI.IReactiveBinding<TView, TProp> BindCommand<TView, TViewModel, TProp, TControl, TParam>(this TView view, TViewModel? viewModel, System.Linq.Expressions.Expression<System.Func<TViewModel, TProp?>> propertyName, System.Linq.Expressions.Expression<System.Func<TView, TControl>> controlName, System.IObservable<TParam?> withParameter, string? toEvent = null)
where TView : class, ReactiveUI.IViewFor<TViewModel>
where TView : class, ReactiveUI.IViewFor
where TViewModel : class
where TProp : System.Windows.Input.ICommand { }
public static ReactiveUI.IReactiveBinding<TView, TProp> BindCommand<TView, TViewModel, TProp, TControl, TParam>(this TView view, TViewModel? viewModel, System.Linq.Expressions.Expression<System.Func<TViewModel, TProp?>> propertyName, System.Linq.Expressions.Expression<System.Func<TView, TControl>> controlName, System.Linq.Expressions.Expression<System.Func<TViewModel, TParam?>> withParameter, string? toEvent = null)
where TView : class, ReactiveUI.IViewFor<TViewModel>
where TView : class, ReactiveUI.IViewFor
where TViewModel : class
where TProp : System.Windows.Input.ICommand { }
}
public class CommandBinderImplementation : Splat.IEnableLogger
{
public CommandBinderImplementation() { }
public ReactiveUI.IReactiveBinding<TView, TProp> BindCommand<TView, TViewModel, TProp, TControl, TParam>(TViewModel? viewModel, TView view, System.Linq.Expressions.Expression<System.Func<TViewModel, TProp?>> vmProperty, System.Linq.Expressions.Expression<System.Func<TView, TControl>> controlProperty, System.IObservable<TParam?> withParameter, string? toEvent = null)
where TView : class, ReactiveUI.IViewFor<TViewModel>
where TView : class, ReactiveUI.IViewFor
where TViewModel : class
where TProp : System.Windows.Input.ICommand { }
public ReactiveUI.IReactiveBinding<TView, TProp> BindCommand<TView, TViewModel, TProp, TControl, TParam>(TViewModel? viewModel, TView view, System.Linq.Expressions.Expression<System.Func<TViewModel, TProp?>> vmProperty, System.Linq.Expressions.Expression<System.Func<TView, TControl>> controlProperty, System.Linq.Expressions.Expression<System.Func<TViewModel, TParam?>> withParameter, string? toEvent = null)
where TView : class, ReactiveUI.IViewFor<TViewModel>
where TView : class, ReactiveUI.IViewFor
where TViewModel : class
where TProp : System.Windows.Input.ICommand { }
}
Expand Down
Loading