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

Housekeeping - Update Spelling and minor code fixes #3649

Merged
merged 4 commits into from
Oct 31, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 6 additions & 8 deletions src/ReactiveUI.Fody.Helpers/ReactiveDependencyAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,17 @@
/// Attribute that marks a property as a Reactive Dependency.
/// </summary>
/// <seealso cref="System.Attribute" />
/// <remarks>
/// Initializes a new instance of the <see cref="ReactiveDependencyAttribute"/> class.
/// </remarks>
/// <param name="targetName">Name of the target.</param>
[AttributeUsage(AttributeTargets.Property)]
public sealed class ReactiveDependencyAttribute : Attribute
public sealed class ReactiveDependencyAttribute(string targetName) : Attribute

Check warning on line 19 in src/ReactiveUI.Fody.Helpers/ReactiveDependencyAttribute.cs

View check run for this annotation

Codecov / codecov/patch

src/ReactiveUI.Fody.Helpers/ReactiveDependencyAttribute.cs#L19

Added line #L19 was not covered by tests
{
/// <summary>
/// Initializes a new instance of the <see cref="ReactiveDependencyAttribute"/> class.
/// </summary>
/// <param name="targetName">Name of the target.</param>
public ReactiveDependencyAttribute(string targetName) => Target = targetName;

/// <summary>
/// Gets the name of the backing property.
/// </summary>
public string Target { get; }
public string Target { get; } = targetName;

Check warning on line 24 in src/ReactiveUI.Fody.Helpers/ReactiveDependencyAttribute.cs

View check run for this annotation

Codecov / codecov/patch

src/ReactiveUI.Fody.Helpers/ReactiveDependencyAttribute.cs#L24

Added line #L24 was not covered by tests

/// <summary>
/// Gets or sets the target property on the backing property.
Expand Down
8 changes: 4 additions & 4 deletions src/ReactiveUI/Activation/ViewForMixins.cs
Original file line number Diff line number Diff line change
Expand Up @@ -227,14 +227,14 @@ public static void WhenActivated(this IActivatableViewModel item, Action<Action<
},
view);

private static IDisposable HandleViewActivation(Func<IEnumerable<IDisposable>> block, IObservable<bool> activation)
private static CompositeDisposable HandleViewActivation(Func<IEnumerable<IDisposable>> block, IObservable<bool> activation)
{
var viewDisposable = new SerialDisposable();

return new CompositeDisposable(
activation.Subscribe(activated =>
{
// NB: We need to make sure to respect ordering so that the cleanup
// NB: We need to make sure to respect ordering so that the clean up
// happens before we invoke block again
viewDisposable.Disposable = Disposable.Empty;
if (activated)
Expand All @@ -245,7 +245,7 @@ private static IDisposable HandleViewActivation(Func<IEnumerable<IDisposable>> b
viewDisposable);
}

private static IDisposable HandleViewModelActivation(IViewFor view, IObservable<bool> activation)
private static CompositeDisposable HandleViewModelActivation(IViewFor view, IObservable<bool> activation)
{
var vmDisposable = new SerialDisposable();
var viewVmDisposable = new SerialDisposable();
Expand All @@ -259,7 +259,7 @@ private static IDisposable HandleViewModelActivation(IViewFor view, IObservable<
.Select(x => x as IActivatableViewModel)
.Subscribe(x =>
{
// NB: We need to make sure to respect ordering so that the cleanup
// NB: We need to make sure to respect ordering so that the clean up
// happens before we activate again
vmDisposable.Disposable = Disposable.Empty;
if (x is not null)
Expand Down
8 changes: 4 additions & 4 deletions src/ReactiveUI/Activation/ViewModelActivator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ public sealed class ViewModelActivator : IDisposable
/// </summary>
public ViewModelActivator()
{
_blocks = new List<Func<IEnumerable<IDisposable>>>();
_activated = new Subject<Unit>();
_deactivated = new Subject<Unit>();
_blocks = new();
_activated = new();
_deactivated = new();
}

/// <summary>
Expand Down Expand Up @@ -111,4 +111,4 @@ public void Dispose()
/// </summary>
/// <param name="block">The block to add.</param>
internal void AddActivationBlock(Func<IEnumerable<IDisposable>> block) => _blocks.Add(block);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -226,4 +226,4 @@ public interface IPropertyBinderImplementation : IEnableLogger
object? conversionHint,
IBindingTypeConverter? vmToViewConverterOverride = null)
where TTarget : class;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.

using System.Diagnostics.CodeAnalysis;
using System.Globalization;

namespace ReactiveUI;
Expand Down Expand Up @@ -257,10 +256,7 @@ bool ViewToVmFunc(TVProp vValue, out TVMProp? vmValue)
}

var setter = _setMethodCache.Get((fromType, targetType));

#pragma warning disable IDE0031 // Use null propagation
return setter is null ? null : setter.PerformSet;
#pragma warning restore IDE0031 // Use null propagation
}

private (IDisposable disposable, IObservable<TValue> value) BindToDirect<TTarget, TValue, TObs>(
Expand Down Expand Up @@ -332,7 +328,7 @@ bool ViewToVmFunc(TVProp vValue, out TVMProp? vmValue)
})
: (() => new IObservedChange<object, object?>[]
{
new ObservedChange<object, object?>(null!, null!, viewModel)
new ObservedChange<object, object?>(null!, null, viewModel)
});

var vFetcher = new Func<IObservedChange<object, object?>[]>(() =>
Expand All @@ -354,7 +350,6 @@ bool ViewToVmFunc(TVProp vValue, out TVMProp? vmValue)
return shouldBind;
}

[SuppressMessage("Roslynator", "RCS1176: Use var instead of explicit", Justification = "Required for generics")]
private IReactiveBinding<TView, (object? view, bool isViewModel)> BindImpl<TViewModel, TView, TVMProp, TVProp, TDontCare>(
TViewModel? viewModel,
TView view,
Expand Down Expand Up @@ -466,4 +461,4 @@ bool ViewToVmFunc(TVProp vValue, out TVMProp? vmValue)
BindingDirection.TwoWay,
disposable);
}
}
}
4 changes: 2 additions & 2 deletions src/ReactiveUI/Bindings/Property/PropertyBindingMixins.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ static PropertyBindingMixins()

/// <summary>
/// Binds the specified view model property to the given view property, and
/// provide a custom view update signaler to signal when the view property has been updated.
/// provide a custom view update signaller to signal when the view property has been updated.
/// </summary>
/// <typeparam name="TViewModel">The type of the view model being bound.</typeparam>
/// <typeparam name="TView">The type of the view being bound.</typeparam>
Expand Down Expand Up @@ -327,4 +327,4 @@ static PropertyBindingMixins()
IBindingTypeConverter? vmToViewConverterOverride = null)
where TTarget : class =>
_binderImplementation.BindTo(@this, target, property, conversionHint, vmToViewConverterOverride);
}
}
6 changes: 3 additions & 3 deletions src/ReactiveUI/Bindings/Reactive/IReactiveBinding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public interface IReactiveBinding<out TView, out TValue> : IDisposable
where TView : IViewFor
{
/// <summary>
/// Gets an expression representing the property on the viewmodel bound to the view.
/// Gets an expression representing the property on the ViewModel bound to the view.
/// This can be a child property, for example x.Foo.Bar.Baz in which case
/// that will be the expression.
/// </summary>
Expand All @@ -29,7 +29,7 @@ public interface IReactiveBinding<out TView, out TValue> : IDisposable
TView View { get; }

/// <summary>
/// Gets an expression representing the property on the view bound to the viewmodel.
/// Gets an expression representing the property on the view bound to the ViewModel.
/// This can be a child property, for example x.Foo.Bar.Baz in which case
/// that will be the expression.
/// </summary>
Expand All @@ -44,4 +44,4 @@ public interface IReactiveBinding<out TView, out TValue> : IDisposable
/// Gets the direction of the binding.
/// </summary>
BindingDirection Direction { get; }
}
}
41 changes: 14 additions & 27 deletions src/ReactiveUI/Bindings/Reactive/ReactiveBinding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,29 @@

namespace ReactiveUI;

internal class ReactiveBinding<TView, TValue> : IReactiveBinding<TView, TValue>
internal class ReactiveBinding<TView, TValue>(
TView view,
Expression viewExpression,
Expression viewModelExpression,
IObservable<TValue?> changed,
BindingDirection direction,
IDisposable bindingDisposable) : IReactiveBinding<TView, TValue>
where TView : IViewFor
{
private readonly IDisposable _bindingDisposable;

public ReactiveBinding(
TView view,
Expression viewExpression,
Expression viewModelExpression,
IObservable<TValue?> changed,
BindingDirection direction,
IDisposable bindingDisposable)
{
View = view;
ViewExpression = viewExpression;
ViewModelExpression = viewModelExpression;
Direction = direction;
Changed = changed;

_bindingDisposable = bindingDisposable;
}

/// <inheritdoc />
public Expression ViewModelExpression { get; }
public Expression ViewModelExpression { get; } = viewModelExpression;

/// <inheritdoc />
public TView View { get; }
public TView View { get; } = view;

/// <inheritdoc />
public Expression ViewExpression { get; }
public Expression ViewExpression { get; } = viewExpression;

/// <inheritdoc />
public IObservable<TValue?> Changed { get; }
public IObservable<TValue?> Changed { get; } = changed;

/// <inheritdoc />
public BindingDirection Direction { get; }
public BindingDirection Direction { get; } = direction;

/// <inheritdoc />
public void Dispose()
Expand All @@ -57,7 +44,7 @@ protected virtual void Dispose(bool isDisposing)
{
if (isDisposing)
{
_bindingDisposable.Dispose();
bindingDisposable.Dispose();
}
}
}
}
16 changes: 4 additions & 12 deletions src/ReactiveUI/Comparers/ChainedComparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,19 @@

namespace ReactiveUI;

internal sealed class ChainedComparer<T> : IComparer<T>
internal sealed class ChainedComparer<T>(IComparer<T>? parent, Comparison<T> comparison) : IComparer<T>
{
private readonly IComparer<T>? _parent;
private readonly Comparison<T> _inner;

public ChainedComparer(IComparer<T>? parent, Comparison<T> comparison)
{
_parent = parent;
_inner = comparison;
}

/// <inheritdoc />
public int Compare(T? x, T? y)
{
var parentResult = _parent?.Compare(x!, y!) ?? 0;
var parentResult = parent?.Compare(x!, y!) ?? 0;

if (x is null && y is null)
{
return 0;
}

return parentResult != 0 ? parentResult : _inner(x!, y!);
return parentResult != 0 ? parentResult : comparison(x!, y!);
}
}
}
6 changes: 3 additions & 3 deletions src/ReactiveUI/Expression/ExpressionRewriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ protected override Expression VisitUnary(UnaryExpression node)
protected override Expression VisitMethodCall(MethodCallExpression node)
{
// Rewrite a method call to an indexer as an index expression
if (node.Arguments.Any(e => !(e is ConstantExpression)) || !node.Method.IsSpecialName)
if (node.Arguments.Any(e => e is not ConstantExpression) || !node.Method.IsSpecialName)
{
throw new NotSupportedException("Index expressions are only supported with constants.");
}
Expand All @@ -120,11 +120,11 @@ protected override Expression VisitMethodCall(MethodCallExpression node)

protected override Expression VisitIndex(IndexExpression node)
{
if (node.Arguments.Any(e => !(e is ConstantExpression)))
if (node.Arguments.Any(e => e is not ConstantExpression))
{
throw new NotSupportedException("Index expressions are only supported with constants.");
}

return base.VisitIndex(node);
}
}
}
4 changes: 2 additions & 2 deletions src/ReactiveUI/Expression/Reflection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ public static class Reflection
/// Gets the appropriate EventArgs derived object for the specified event name for a Type.
/// </summary>
/// <param name="type">The type of object to find the event on.</param>
/// <param name="eventName">The mame of the event.</param>
/// <param name="eventName">The name of the event.</param>
/// <returns>The Type of the EventArgs to use.</returns>
/// <exception cref="Exception">If there is no event matching the name on the target type.</exception>
public static Type GetEventArgsTypeForEvent(Type type, string? eventName) // TODO: Create Test
Expand Down Expand Up @@ -398,4 +398,4 @@ public static class Reflection
.Where(x => x is not null)
.Select(x => ((TViewModel?)x).WhenAnyDynamic(expression, y => y.Value))
.Switch()!;
}
}
2 changes: 1 addition & 1 deletion src/ReactiveUI/Interfaces/ICreatesObservableForProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ public interface ICreatesObservableForProperty : IEnableLogger
/// property on the object changes. If this cannot be done for a
/// specified value of beforeChanged, return Observable.Never.</returns>
IObservable<IObservedChange<object?, object?>> GetNotificationForProperty(object sender, Expression expression, string propertyName, bool beforeChanged = false, bool suppressWarnings = false);
}
}
29 changes: 11 additions & 18 deletions src/ReactiveUI/Interfaces/ObservedChange.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,20 @@ namespace ReactiveUI;
/// </summary>
/// <typeparam name="TSender">The sender type.</typeparam>
/// <typeparam name="TValue">The value type.</typeparam>
public class ObservedChange<TSender, TValue> : IObservedChange<TSender, TValue>
/// <remarks>
/// Initializes a new instance of the <see cref="ObservedChange{TSender, TValue}"/> class.
/// </remarks>
/// <param name="sender">The sender.</param>
/// <param name="expression">Expression describing the member.</param>
/// <param name="value">The value.</param>
public class ObservedChange<TSender, TValue>(TSender sender, Expression? expression, TValue value) : IObservedChange<TSender, TValue>
{
/// <summary>
/// Initializes a new instance of the <see cref="ObservedChange{TSender, TValue}"/> class.
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="expression">Expression describing the member.</param>
/// <param name="value">The value.</param>
public ObservedChange(TSender sender, Expression? expression, TValue value)
{
Sender = sender;
Expression = expression;
Value = value;
}

/// <inheritdoc/>
public TSender Sender { get; }
public TSender Sender { get; } = sender;

/// <inheritdoc/>
public Expression? Expression { get; }
public Expression? Expression { get; } = expression;

/// <inheritdoc/>
public TValue Value { get; }
}
public TValue Value { get; } = value;
}
22 changes: 8 additions & 14 deletions src/ReactiveUI/Interfaces/ReactivePropertyChangedEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,23 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.

using System.ComponentModel;

namespace ReactiveUI;

/// <summary>
/// Event arguments for when a property has changed.
/// Expands on the PropertyChangedEventArgs to add the Sender.
/// </summary>
/// <typeparam name="TSender">The sender type.</typeparam>
public class ReactivePropertyChangedEventArgs<TSender> : PropertyChangedEventArgs, IReactivePropertyChangedEventArgs<TSender>
/// <remarks>
/// Initializes a new instance of the <see cref="ReactivePropertyChangedEventArgs{TSender}"/> class.
/// </remarks>
/// <param name="sender">The sender.</param>
/// <param name="propertyName">Name of the property.</param>
public class ReactivePropertyChangedEventArgs<TSender>(TSender sender, string propertyName) : PropertyChangedEventArgs(propertyName), IReactivePropertyChangedEventArgs<TSender>
{
/// <summary>
/// Initializes a new instance of the <see cref="ReactivePropertyChangedEventArgs{TSender}"/> class.
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="propertyName">Name of the property.</param>
public ReactivePropertyChangedEventArgs(TSender sender, string propertyName)
: base(propertyName) =>
Sender = sender;

/// <summary>
/// Gets the sender which triggered the property changed event.
/// </summary>
/// <inheritdoc/>
public TSender Sender { get; }
}
public TSender Sender { get; } = sender;
}