Skip to content

Commit

Permalink
Fix: Make Bind() ViewModel parameters nullable. (#2468)
Browse files Browse the repository at this point in the history
  • Loading branch information
Noggog authored Jul 31, 2020
1 parent a8ff550 commit 2744294
Show file tree
Hide file tree
Showing 13 changed files with 63 additions and 63 deletions.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace ReactiveUI.Winforms
public class ContentControlBindingHook : ReactiveUI.IPropertyBindingHook
{
public ContentControlBindingHook() { }
public bool ExecuteHook(object source, object target, System.Func<ReactiveUI.IObservedChange<, >[]> getCurrentViewModelProperties, System.Func<ReactiveUI.IObservedChange<, >[]> getCurrentViewProperties, ReactiveUI.BindingDirection direction) { }
public bool ExecuteHook(object? source, object target, System.Func<ReactiveUI.IObservedChange<, >[]> getCurrentViewModelProperties, System.Func<ReactiveUI.IObservedChange<, >[]> getCurrentViewProperties, ReactiveUI.BindingDirection direction) { }
}
public class CreatesWinformsCommandBinding : ReactiveUI.ICreatesCommandBinding
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace ReactiveUI.Winforms
public class ContentControlBindingHook : ReactiveUI.IPropertyBindingHook
{
public ContentControlBindingHook() { }
public bool ExecuteHook(object source, object target, System.Func<ReactiveUI.IObservedChange<, >[]> getCurrentViewModelProperties, System.Func<ReactiveUI.IObservedChange<, >[]> getCurrentViewProperties, ReactiveUI.BindingDirection direction) { }
public bool ExecuteHook(object? source, object target, System.Func<ReactiveUI.IObservedChange<, >[]> getCurrentViewModelProperties, System.Func<ReactiveUI.IObservedChange<, >[]> getCurrentViewProperties, ReactiveUI.BindingDirection direction) { }
}
public class CreatesWinformsCommandBinding : ReactiveUI.ICreatesCommandBinding
{
Expand Down
2 changes: 1 addition & 1 deletion src/ReactiveUI.Winforms/ContentControlBindingHook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace ReactiveUI.Winforms
public class ContentControlBindingHook : IPropertyBindingHook
{
/// <inheritdoc/>
public bool ExecuteHook(object source, object target, Func<IObservedChange<object, object>[]> getCurrentViewModelProperties, Func<IObservedChange<object, object>[]> getCurrentViewProperties, BindingDirection direction)
public bool ExecuteHook(object? source, object target, Func<IObservedChange<object, object>[]> getCurrentViewModelProperties, Func<IObservedChange<object, object>[]> getCurrentViewProperties, BindingDirection direction)
{
if (getCurrentViewProperties == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public interface IPropertyBinderImplementation : IEnableLogger
/// disconnects the binding.
/// </returns>
IReactiveBinding<TView, TViewModel, (object? view, bool isViewModel)>? Bind<TViewModel, TView, TVMProp, TVProp, TDontCare>(
TViewModel viewModel,
TViewModel? viewModel,
TView view,
Expression<Func<TViewModel, TVMProp>> vmProperty,
Expression<Func<TView, TVProp>> viewProperty,
Expand Down Expand Up @@ -122,7 +122,7 @@ public interface IPropertyBinderImplementation : IEnableLogger
/// disconnects the binding.
/// </returns>
IReactiveBinding<TView, TViewModel, (object? view, bool isViewModel)>? Bind<TViewModel, TView, TVMProp, TVProp, TDontCare>(
TViewModel viewModel,
TViewModel? viewModel,
TView view,
Expression<Func<TViewModel, TVMProp>> vmProperty,
Expression<Func<TView, TVProp>> viewProperty,
Expand Down Expand Up @@ -172,7 +172,7 @@ public interface IPropertyBinderImplementation : IEnableLogger
/// There is no registered converter from <typeparamref name="TVMProp"/> to <typeparamref name="TVProp"/>.
/// </exception>
IReactiveBinding<TView, TViewModel, TVProp>? OneWayBind<TViewModel, TView, TVMProp, TVProp>(
TViewModel viewModel,
TViewModel? viewModel,
TView view,
Expression<Func<TViewModel, TVMProp>> vmProperty,
Expression<Func<TView, TVProp>> viewProperty,
Expand Down Expand Up @@ -213,7 +213,7 @@ public interface IPropertyBinderImplementation : IEnableLogger
/// disconnects the binding.
/// </returns>
IReactiveBinding<TView, TViewModel, TOut>? OneWayBind<TViewModel, TView, TProp, TOut>(
TViewModel viewModel,
TViewModel? viewModel,
TView view,
Expression<Func<TViewModel, TProp>> vmProperty,
Expression<Func<TView, TOut>> viewProperty,
Expand Down
16 changes: 8 additions & 8 deletions src/ReactiveUI/Bindings/Property/PropertyBinderImplementation.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2019 .NET Foundation and Contributors. All rights reserved.
// Copyright (c) 2019 .NET Foundation and Contributors. All rights reserved.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.
Expand Down Expand Up @@ -48,7 +48,7 @@ public class PropertyBinderImplementation : IPropertyBinderImplementation

/// <inheritdoc />
public IReactiveBinding<TView, TViewModel, (object? view, bool isViewModel)> Bind<TViewModel, TView, TVMProp, TVProp, TDontCare>(
TViewModel viewModel,
TViewModel? viewModel,
TView view,
Expression<Func<TViewModel, TVMProp>> vmProperty,
Expression<Func<TView, TVProp>> viewProperty,
Expand Down Expand Up @@ -95,7 +95,7 @@ bool ViewToVmFunc(TVProp vValue, out TVMProp vmValue)

/// <inheritdoc />
public IReactiveBinding<TView, TViewModel, (object? view, bool isViewModel)>? Bind<TViewModel, TView, TVMProp, TVProp, TDontCare>(
TViewModel viewModel,
TViewModel? viewModel,
TView view,
Expression<Func<TViewModel, TVMProp>> vmProperty,
Expression<Func<TView, TVProp>> viewProperty,
Expand Down Expand Up @@ -142,7 +142,7 @@ bool ViewToVmFunc(TVProp vValue, out TVMProp vmValue)

/// <inheritdoc />
public IReactiveBinding<TView, TViewModel, TVProp>? OneWayBind<TViewModel, TView, TVMProp, TVProp>(
TViewModel viewModel,
TViewModel? viewModel,
TView view,
Expression<Func<TViewModel, TVMProp>> vmProperty,
Expression<Func<TView, TVProp>> viewProperty,
Expand Down Expand Up @@ -195,7 +195,7 @@ bool ViewToVmFunc(TVProp vValue, out TVMProp vmValue)

/// <inheritdoc />
public IReactiveBinding<TView, TViewModel, TOut>? OneWayBind<TViewModel, TView, TProp, TOut>(
TViewModel viewModel,
TViewModel? viewModel,
TView view,
Expression<Func<TViewModel, TProp>> vmProperty,
Expression<Func<TView, TOut>> viewProperty,
Expand Down Expand Up @@ -357,7 +357,7 @@ public IDisposable BindTo<TValue, TTarget, TTValue>(
return (setObservable.Subscribe(_ => { }, ex => this.Log().Error(ex, $"{viewExpression} Binding received an Exception!")), setObservable);
}

private bool EvalBindingHooks<TViewModel, TView>(TViewModel viewModel, TView view, Expression vmExpression, Expression viewExpression, BindingDirection direction)
private bool EvalBindingHooks<TViewModel, TView>(TViewModel? viewModel, TView view, Expression vmExpression, Expression viewExpression, BindingDirection direction)
where TViewModel : class
{
var hooks = Locator.Current.GetServices<IPropertyBindingHook>();
Expand All @@ -380,7 +380,7 @@ private bool EvalBindingHooks<TViewModel, TView>(TViewModel viewModel, TView vie
{
vmFetcher = () => new IObservedChange<object, object?>[]
{
new ObservedChange<object, object>(null!, null!, viewModel)
new ObservedChange<object, object?>(null!, null!, viewModel)
};
}

Expand All @@ -404,7 +404,7 @@ private bool EvalBindingHooks<TViewModel, TView>(TViewModel viewModel, TView vie
}

private IReactiveBinding<TView, TViewModel, (object? view, bool isViewModel)> BindImpl<TViewModel, TView, TVMProp, TVProp, TDontCare>(
TViewModel viewModel,
TViewModel? viewModel,
TView view,
Expression<Func<TViewModel, TVMProp>> vmProperty,
Expression<Func<TView, TVProp>> viewProperty,
Expand Down
12 changes: 6 additions & 6 deletions src/ReactiveUI/Bindings/Property/PropertyBindingMixins.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ static PropertyBindingMixins()
/// </returns>
public static IReactiveBinding<TView, TViewModel, (object? view, bool isViewModel)>? Bind<TViewModel, TView, TVMProp, TVProp>(
this TView view,
TViewModel viewModel,
TViewModel? viewModel,
Expression<Func<TViewModel, TVMProp>> vmProperty,
Expression<Func<TView, TVProp>> viewProperty,
object? conversionHint = null,
Expand Down Expand Up @@ -126,7 +126,7 @@ static PropertyBindingMixins()
/// </returns>
public static IReactiveBinding<TView, TViewModel, (object? view, bool isViewModel)>? Bind<TViewModel, TView, TVMProp, TVProp, TDontCare>(
this TView view,
TViewModel viewModel,
TViewModel? viewModel,
Expression<Func<TViewModel, TVMProp>> vmProperty,
Expression<Func<TView, TVProp>> viewProperty,
IObservable<TDontCare>? signalViewUpdate,
Expand Down Expand Up @@ -170,7 +170,7 @@ static PropertyBindingMixins()
/// </returns>
public static IReactiveBinding<TView, TViewModel, (object? view, bool isViewModel)>? Bind<TViewModel, TView, TVMProp, TVProp>(
this TView view,
TViewModel viewModel,
TViewModel? viewModel,
Expression<Func<TViewModel, TVMProp>> vmProperty,
Expression<Func<TView, TVProp>> viewProperty,
Func<TVMProp, TVProp> vmToViewConverter,
Expand Down Expand Up @@ -220,7 +220,7 @@ static PropertyBindingMixins()
/// </returns>
public static IReactiveBinding<TView, TViewModel, (object? view, bool isViewModel)>? Bind<TViewModel, TView, TVMProp, TVProp, TDontCare>(
this TView view,
TViewModel viewModel,
TViewModel? viewModel,
Expression<Func<TViewModel, TVMProp>> vmProperty,
Expression<Func<TView, TVProp>> viewProperty,
IObservable<TDontCare>? signalViewUpdate,
Expand Down Expand Up @@ -270,7 +270,7 @@ static PropertyBindingMixins()
/// </returns>
public static IReactiveBinding<TView, TViewModel, TVProp>? OneWayBind<TViewModel, TView, TVMProp, TVProp>(
this TView view,
TViewModel viewModel,
TViewModel? viewModel,
Expression<Func<TViewModel, TVMProp>> vmProperty,
Expression<Func<TView, TVProp>> viewProperty,
object? conversionHint = null,
Expand Down Expand Up @@ -319,7 +319,7 @@ static PropertyBindingMixins()
/// </returns>
public static IReactiveBinding<TView, TViewModel, TOut>? OneWayBind<TViewModel, TView, TProp, TOut>(
this TView view,
TViewModel viewModel,
TViewModel? viewModel,
Expression<Func<TViewModel, TProp>> vmProperty,
Expression<Func<TView, TOut>> viewProperty,
Func<TProp, TOut> selector)
Expand Down
2 changes: 1 addition & 1 deletion src/ReactiveUI/Bindings/Reactive/IReactiveBinding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public interface IReactiveBinding<out TView, out TViewModel, out TValue> : IDisp
/// <summary>
/// Gets the instance of the view model this binding is applied to.
/// </summary>
TViewModel ViewModel { get; }
TViewModel? ViewModel { get; }

/// <summary>
/// Gets an expression representing the propertyon the viewmodel bound to the view.
Expand Down
4 changes: 2 additions & 2 deletions src/ReactiveUI/Bindings/Reactive/ReactiveBinding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ internal class ReactiveBinding<TView, TViewModel, TValue> : IReactiveBinding<TVi

public ReactiveBinding(
TView view,
TViewModel viewModel,
TViewModel? viewModel,
Expression viewExpression,
Expression viewModelExpression,
IObservable<TValue> changed,
Expand All @@ -34,7 +34,7 @@ public ReactiveBinding(
}

/// <inheritdoc />
public TViewModel ViewModel { get; }
public TViewModel? ViewModel { get; }

/// <inheritdoc />
public Expression ViewModelExpression { get; }
Expand Down
2 changes: 1 addition & 1 deletion src/ReactiveUI/Expression/Reflection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ public static bool IsStatic(this PropertyInfo item)
}

[SuppressMessage("Microsoft.Performance", "CA1801", Justification = "TViewModel used to help generic calling.")]
internal static IObservable<object> ViewModelWhenAnyValue<TView, TViewModel>(TViewModel viewModel, TView view, Expression expression)
internal static IObservable<object> ViewModelWhenAnyValue<TView, TViewModel>(TViewModel? viewModel, TView view, Expression expression)
where TView : class, IViewFor
where TViewModel : class
{
Expand Down
2 changes: 1 addition & 1 deletion src/ReactiveUI/Interfaces/IPropertyBindingHook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public interface IPropertyBindingHook
/// <param name="getCurrentViewProperties">Get current view properties.</param>
/// <param name="direction">The Binding direction.</param>
bool ExecuteHook(
object source,
object? source,
object target,
Func<IObservedChange<object, object>[]> getCurrentViewModelProperties,
Func<IObservedChange<object, object>[]> getCurrentViewProperties,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public class AutoDataTemplateBindingHook : IPropertyBindingHook
});

/// <inheritdoc/>
public bool ExecuteHook(object source, object target, Func<IObservedChange<object, object>[]> getCurrentViewModelProperties, Func<IObservedChange<object, object>[]> getCurrentViewProperties, BindingDirection direction)
public bool ExecuteHook(object? source, object target, Func<IObservedChange<object, object>[]> getCurrentViewModelProperties, Func<IObservedChange<object, object>[]> getCurrentViewProperties, BindingDirection direction)
{
if (getCurrentViewProperties == null)
{
Expand Down

0 comments on commit 2744294

Please sign in to comment.