Skip to content

Commit

Permalink
Housekeeping: Update Obsolete notation to fix warnings (#3561)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisPulman committed Jul 8, 2023
1 parent c5742c8 commit 9d73fba
Show file tree
Hide file tree
Showing 28 changed files with 166 additions and 144 deletions.
6 changes: 3 additions & 3 deletions src/Directory.build.props
Expand Up @@ -45,9 +45,9 @@

<ItemGroup Condition="$(IsTestProject)">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.3" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.console" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5" />
<PackageReference Include="xunit" Version="2.5.0" />
<PackageReference Include="xunit.runner.console" Version="2.5.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.0" />
<PackageReference Include="Xunit.StaFact" Version="1.1.11" />
<PackageReference Include="FluentAssertions" Version="6.11.0" />
<PackageReference Include="Microsoft.Reactive.Testing" Version="6.0.0" />
Expand Down
13 changes: 0 additions & 13 deletions src/Directory.build.targets
Expand Up @@ -10,22 +10,9 @@
<PropertyGroup Condition="$(TargetFramework.StartsWith('netstandard'))">
<DefineConstants>$(DefineConstants);NETSTANDARD;PORTABLE</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="$(TargetFramework.StartsWith('netcoreapp'))">
<DefineConstants>$(DefineConstants);NETCOREAPP</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="$(TargetFramework.StartsWith('netcoreapp2'))">
<DefineConstants>$(DefineConstants);NETCOREAPP2</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="$(TargetFramework.StartsWith('netcoreapp3'))">
<DefineConstants>$(DefineConstants);NETCOREAPP3</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="$(TargetFramework.StartsWith('net4'))">
<DefineConstants>$(DefineConstants);NET_461;XAML</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="$(TargetFramework.StartsWith('uap'))">
<TargetPlatformVersion>10.0.16299.0</TargetPlatformVersion>
<DefineConstants>$(DefineConstants);NETFX_CORE;XAML;WINDOWS_UWP</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="$(TargetFramework.StartsWith('Xamarin.iOS'))">
<DefineConstants>$(DefineConstants);MONO;UIKIT;COCOA;IOS</DefineConstants>
</PropertyGroup>
Expand Down
4 changes: 1 addition & 3 deletions src/ReactiveUI.Blend/ReactiveUI.Blend.csproj
Expand Up @@ -16,12 +16,10 @@
</ItemGroup>

<ItemGroup Condition=" $(TargetFramework.StartsWith('net4')) ">
<Compile Include="Platforms\net4\**\*.cs" />
<Reference Include="PresentationFramework.Aero" />
<PackageReference Include="Microsoft.Xaml.Behaviors.Wpf" Version="1.1.39" />
</ItemGroup>

<ItemGroup Condition="$(TargetFramework.EndsWith('-windows10.0.17763.0'))">
<ItemGroup>
<Compile Include="Platforms\net4\**\*.cs" />
<PackageReference Include="Microsoft.Xaml.Behaviors.Wpf" Version="1.1.39" />
</ItemGroup>
Expand Down
Expand Up @@ -6,6 +6,7 @@
<PackageDescription>Rosyln extension that checks correct usage of the Fody extension.</PackageDescription>
<PackageTags>mvvm;reactiveui;rx;reactive extensions;observable;LINQ;events;frp;xamarin;android;ios;mac;forms;monodroid;monotouch;xamarin.android;xamarin.ios;xamarin.forms;xamarin.mac;xamarin.tvos;wpf;net;netstandard;net472;uwp;tizen;unoplatform;fody;</PackageTags>
<IsPackable>False</IsPackable>
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
</PropertyGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions src/ReactiveUI.Fody/ObservableAsPropertyWeaver.cs
Expand Up @@ -99,7 +99,7 @@ public void Execute()
targetType.Fields.Add(field);

// It's an auto-property, so remove the generated field
if (property.SetMethod is not null && property.SetMethod.HasBody)
if (property.SetMethod?.HasBody == true)
{
// Remove old field (the generated backing field for the auto property)
var oldField = (FieldReference)property.GetMethod.Body.Instructions.Single(x => x.Operand is FieldReference).Operand;
Expand Down Expand Up @@ -188,4 +188,4 @@ public void EmitDefaultValue(MethodBody methodBody, ILProcessor il, TypeReferenc
}
}
}
}
}
23 changes: 4 additions & 19 deletions src/ReactiveUI.Fody/ReactiveDependencyPropertyWeaver.cs
Expand Up @@ -77,24 +77,9 @@ public void Execute()
var reactiveObject = new TypeReference("ReactiveUI", "IReactiveObject", ModuleDefinition, reactiveUI);

var targetTypes = ModuleDefinition.GetAllTypes().Where(x => x.BaseType is not null && reactiveObject.IsAssignableFrom(x.BaseType)).ToArray();
var reactiveObjectExtensions = new TypeReference("ReactiveUI", "IReactiveObjectExtensions", ModuleDefinition, reactiveUI).Resolve();
if (reactiveObjectExtensions is null)
{
throw new Exception("reactiveObjectExtensions is null");
}

var raisePropertyChangedMethod = ModuleDefinition.ImportReference(reactiveObjectExtensions.Methods.Single(x => x.Name == "RaisePropertyChanged"));
if (raisePropertyChangedMethod is null)
{
throw new Exception("raisePropertyChangedMethod is null");
}

var reactiveDependencyAttribute = ModuleDefinition.FindType("ReactiveUI.Fody.Helpers", "ReactiveDependencyAttribute", helpers);
if (reactiveDependencyAttribute is null)
{
throw new Exception("reactiveDecoratorAttribute is null");
}

var reactiveObjectExtensions = new TypeReference("ReactiveUI", "IReactiveObjectExtensions", ModuleDefinition, reactiveUI).Resolve() ?? throw new Exception("reactiveObjectExtensions is null");
var raisePropertyChangedMethod = ModuleDefinition.ImportReference(reactiveObjectExtensions.Methods.Single(x => x.Name == "RaisePropertyChanged")) ?? throw new Exception("raisePropertyChangedMethod is null");
var reactiveDependencyAttribute = ModuleDefinition.FindType("ReactiveUI.Fody.Helpers", "ReactiveDependencyAttribute", helpers) ?? throw new Exception("reactiveDecoratorAttribute is null");
foreach (var targetType in targetTypes.Where(x => x.Properties.Any(y => y.IsDefined(reactiveDependencyAttribute))).ToArray())
{
foreach (var facadeProperty in targetType.Properties.Where(x => x.IsDefined(reactiveDependencyAttribute)).ToArray())
Expand Down Expand Up @@ -240,4 +225,4 @@ public void Execute()
}
}
}
}
}
23 changes: 4 additions & 19 deletions src/ReactiveUI.Fody/ReactiveUIPropertyWeaver.cs
Expand Up @@ -79,24 +79,9 @@ public void Execute()
LogInfo?.Invoke($"{helpers.Name} {helpers.Version}");
var reactiveObject = new TypeReference("ReactiveUI", "IReactiveObject", ModuleDefinition, reactiveUI);
var targetTypes = ModuleDefinition.GetAllTypes().Where(x => x.BaseType is not null && reactiveObject.IsAssignableFrom(x.BaseType)).ToArray();
var reactiveObjectExtensions = new TypeReference("ReactiveUI", "IReactiveObjectExtensions", ModuleDefinition, reactiveUI).Resolve();
if (reactiveObjectExtensions is null)
{
throw new Exception("reactiveObjectExtensions is null");
}

var raiseAndSetIfChangedMethod = ModuleDefinition.ImportReference(reactiveObjectExtensions.Methods.Single(x => x.Name == "RaiseAndSetIfChanged"));
if (raiseAndSetIfChangedMethod is null)
{
throw new Exception("raiseAndSetIfChangedMethod is null");
}

var reactiveAttribute = ModuleDefinition.FindType("ReactiveUI.Fody.Helpers", "ReactiveAttribute", helpers);
if (reactiveAttribute is null)
{
throw new Exception("reactiveAttribute is null");
}

var reactiveObjectExtensions = new TypeReference("ReactiveUI", "IReactiveObjectExtensions", ModuleDefinition, reactiveUI).Resolve() ?? throw new Exception("reactiveObjectExtensions is null");
var raiseAndSetIfChangedMethod = ModuleDefinition.ImportReference(reactiveObjectExtensions.Methods.Single(x => x.Name == "RaiseAndSetIfChanged")) ?? throw new Exception("raiseAndSetIfChangedMethod is null");
var reactiveAttribute = ModuleDefinition.FindType("ReactiveUI.Fody.Helpers", "ReactiveAttribute", helpers) ?? throw new Exception("reactiveAttribute is null");
foreach (var targetType in targetTypes)
{
foreach (var property in targetType.Properties.Where(x => x.IsDefined(reactiveAttribute)).ToArray())
Expand Down Expand Up @@ -174,4 +159,4 @@ public void Execute()
}
}
}
}
}
Expand Up @@ -4,6 +4,7 @@
// See the LICENSE file in the project root for full license information.

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq.Expressions;
using System.Reactive.Concurrency;
Expand Down Expand Up @@ -183,5 +184,20 @@ public void SmokeTestWinformControls()

disp.Dispose();
}

[Fact]
public void PanelSetMethodBindingConverter_GetAffinityForObjects()
{
var fixture = new PanelSetMethodBindingConverter();
var test1 = fixture.GetAffinityForObjects(typeof(List<Control>), typeof(Control.ControlCollection));
var test2 = fixture.GetAffinityForObjects(typeof(List<TextBox>), typeof(Control.ControlCollection));
var test3 = fixture.GetAffinityForObjects(typeof(List<Label>), typeof(Control.ControlCollection));
var test4 = fixture.GetAffinityForObjects(typeof(Control.ControlCollection), typeof(IEnumerable<GridItem>));

Assert.Equal(0, test1);
Assert.Equal(10, test2);
Assert.Equal(10, test3);
Assert.Equal(0, test4);
}
}
}
Expand Up @@ -10,8 +10,6 @@ namespace ReactiveUI.Tests.Wpf
{
public class WpfActiveContentApp : Application
{
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.

/// <summary>
/// Gets the mock window factory.
/// </summary>
Expand All @@ -35,7 +33,5 @@ public class WpfActiveContentApp : Application
/// The WPF test window factory.
/// </value>
public Func<WpfTestWindow> WpfTestWindowFactory { get; } = () => new();

#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
}
}
Expand Up @@ -16,9 +16,8 @@ namespace ReactiveUI.Tests.Wpf
/// <seealso cref="System.IDisposable" />
public class WpfActiveContentFixture : IDisposable
{
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
private readonly Thread? _uiThread;
private bool _loadComplete;
private Thread _uiThread;
private bool _disposedValue;

/// <summary>
Expand Down Expand Up @@ -69,11 +68,9 @@ protected virtual void Dispose(bool disposing)
() => App.Shutdown(),
DispatcherPriority.Normal);
Thread.Sleep(500);
_uiThread.Join();
_uiThread?.Join();
_disposedValue = true;
}
}

#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
}
}
1 change: 0 additions & 1 deletion src/ReactiveUI.Uwp/Common/AutoDataTemplateBindingHook.cs
Expand Up @@ -38,7 +38,6 @@ public class AutoDataTemplateBindingHook : IPropertyBindingHook
/// <summary>
/// Gets the default item template.
/// </summary>
[SuppressMessage("Design", "CA1307: Use the currency locale settings", Justification = "Not available on all platforms.")]
public static Lazy<DataTemplate> DefaultItemTemplate { get; } = new(() =>
{
#if NETFX_CORE || HAS_UNO
Expand Down
1 change: 0 additions & 1 deletion src/ReactiveUI.Uwp/Common/BooleanToVisibilityHint.cs
Expand Up @@ -15,7 +15,6 @@ namespace ReactiveUI
/// <summary>
/// Enum that hints at the visibility of a ui element.
/// </summary>
[SuppressMessage("Name", "CA1714: Flags enums should have plural names", Justification = "For legacy support")]
[Flags]
public enum BooleanToVisibilityHint
{
Expand Down
2 changes: 2 additions & 0 deletions src/ReactiveUI.Uwp/Common/PlatformOperations.cs
Expand Up @@ -33,7 +33,9 @@ public class PlatformOperations : IPlatformOperations
return null;
}
#else
#pragma warning disable IDE0022 // Use expression body for method
return null;
#pragma warning restore IDE0022 // Use expression body for method
#endif
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/ReactiveUI.Uwp/Common/ReactiveUserControl.cs
Expand Up @@ -88,12 +88,11 @@ namespace ReactiveUI
#if HAS_UNO && IOS
[global::Foundation.Register]
#endif
[SuppressMessage("Design", "CA1010:Collections should implement generic interface", Justification = "Deliberate usage")]
public
#if HAS_UNO
partial
#endif
class ReactiveUserControl<TViewModel> :
class ReactiveUserControl<TViewModel> :
UserControl, IViewFor<TViewModel>
where TViewModel : class
{
Expand Down
20 changes: 6 additions & 14 deletions src/ReactiveUI.Uwp/Common/RoutedViewHost.cs
Expand Up @@ -106,15 +106,13 @@ public RoutedViewHost()
this.WhenAnyObservable(x => x.ViewContractObservable).Do(x => _viewContract = x).StartWith(ViewContract),
(viewModel, contract) => (viewModel, contract));

// NB: The DistinctUntilChanged is useful because most views in
// WinRT will end up getting here twice - once for configuring
// the RoutedViewHost's ViewModel, and once on load via SizeChanged
this.WhenActivated(d =>
{
// NB: The DistinctUntilChanged is useful because most views in
// WinRT will end up getting here twice - once for configuring
// the RoutedViewHost's ViewModel, and once on load via SizeChanged
d(vmAndContract.DistinctUntilChanged<(IRoutableViewModel? viewModel, string? contract)>().Subscribe(
d(vmAndContract.DistinctUntilChanged().Subscribe(
ResolveViewForViewModel,
ex => RxApp.DefaultExceptionHandler.OnNext(ex)));
});
ex => RxApp.DefaultExceptionHandler.OnNext(ex))));
}

/// <summary>
Expand Down Expand Up @@ -174,13 +172,7 @@ private void ResolveViewForViewModel((IRoutableViewModel? viewModel, string? con
}

var viewLocator = ViewLocator ?? ReactiveUI.ViewLocator.Current;
var view = viewLocator.ResolveView(x.viewModel, x.contract) ?? viewLocator.ResolveView(x.viewModel);

if (view is null)
{
throw new Exception($"Couldn't find view for '{x.viewModel}'.");
}

var view = (viewLocator.ResolveView(x.viewModel, x.contract) ?? viewLocator.ResolveView(x.viewModel)) ?? throw new Exception($"Couldn't find view for '{x.viewModel}'.");
view.ViewModel = x.viewModel;
Content = view;
}
Expand Down
2 changes: 1 addition & 1 deletion src/ReactiveUI.Uwp/Common/ViewModelViewHost.cs
Expand Up @@ -95,7 +95,7 @@ public ViewModelViewHost()
: Observable.FromEvent<SizeChangedEventHandler, string?>(
eventHandler =>
{
void Handler(object? sender, SizeChangedEventArgs e) => eventHandler(platformGetter()!);
void Handler(object? sender, SizeChangedEventArgs e) => eventHandler(platformGetter());
return Handler;
},
x => SizeChanged += x,
Expand Down
3 changes: 2 additions & 1 deletion src/ReactiveUI.Uwp/Rx/Linq/DispatcherObservable.cs
Expand Up @@ -141,6 +141,7 @@ public static IObservable<TSource> ObserveOn<TSource>(this IObservable<TSource>
/// <param name="source">Source sequence.</param>
/// <returns>The source sequence whose observations happen on the current thread's dispatcher.</returns>
/// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
[Obsolete("Use ObserveOn(RxApp.MainThreadScheduler)", false)]
public static IObservable<TSource> ObserveOnDispatcher<TSource>(this IObservable<TSource> source)
{
if (source == null)
Expand Down Expand Up @@ -377,4 +378,4 @@ private static IObservable<TSource> SubscribeOn_<TSource>(IObservable<TSource> s
}

#endregion
}
}
13 changes: 4 additions & 9 deletions src/ReactiveUI.Winforms/PanelSetMethodBindingConverter.cs
Expand Up @@ -23,14 +23,9 @@ public int GetAffinityForObjects(Type? fromType, Type? toType)
return 0;
}

#pragma warning disable IDE0046 // Convert to conditional expression
if (fromType?.GetInterfaces().Any(x => x.IsGenericType && x.GetGenericTypeDefinition() == typeof(IEnumerable<>) && x.GetGenericArguments()[0].IsSubclassOf(typeof(Control))) ?? false)
#pragma warning restore IDE0046 // Convert to conditional expression
{
return 10;
}

return 0;
return fromType?.GetInterfaces().Any(x => x.IsGenericType && x.GetGenericTypeDefinition() == typeof(IEnumerable<>) && x.GetGenericArguments()[0].IsSubclassOf(typeof(Control))) ?? false
? 10
: 0;
}

/// <inheritdoc />
Expand All @@ -57,4 +52,4 @@ public object PerformSet(object? toTarget, object? newValue, object?[]? argument

return targetCollection;
}
}
}
14 changes: 2 additions & 12 deletions src/ReactiveUI.Winforms/ReactiveUI.Winforms.csproj
Expand Up @@ -8,30 +8,20 @@
<PackageId>ReactiveUI.WinForms</PackageId>
<UseWindowsForms>true</UseWindowsForms>
<PackageTags>mvvm;reactiveui;rx;reactive extensions;observable;LINQ;events;frp;winforms;net;net472;</PackageTags>
<NoWarn>$(NoWarn);IDE1006;</NoWarn>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\ReactiveUI\ReactiveUI.csproj" />
</ItemGroup>

<ItemGroup>
<None Include="..\ReactiveUI.Uwp\Rx\**\*.cs" LinkBase="Rx" />
<None Include="..\ReactiveUI.Uwp\Rx\**\*.cs" LinkBase="Rx" Exclude="..\ReactiveUI.Uwp\Rx\Concurrency\DispatcherScheduler.cs" />
</ItemGroup>

<ItemGroup Condition="$(TargetFramework.EndsWith('-windows10.0.17763.0'))">
<Compile Include="..\ReactiveUI.Uwp\Rx\Concurrency\ControlScheduler.cs" LinkBase="Rx" />
<Compile Include="..\ReactiveUI.Uwp\Rx\Internal\Constants.cs" LinkBase="Rx" />
<Compile Include="..\ReactiveUI.Uwp\Rx\Linq\**\*.cs" LinkBase="Rx" Exclude="..\ReactiveUI.Uwp\Rx\Linq\DispatcherObservable.cs" />
</ItemGroup>

<ItemGroup>
<Compile Update="RoutedViewHost.Designer.cs">
<SubType>UserControl</SubType>
<DependentUpon>RoutedViewHost.cs</DependentUpon>
</Compile>
<Compile Update="ReactiveUserControl.Designer.cs">
<SubType>UserControl</SubType>
<DependentUpon>ReactiveUserControl.cs</DependentUpon>
</Compile>
</ItemGroup>
</Project>
10 changes: 2 additions & 8 deletions src/ReactiveUI.Winforms/WinformsCreatesObservableForProperty.cs
Expand Up @@ -48,13 +48,7 @@ public int GetAffinityForObject(Type type, string propertyName, bool beforeChang
throw new ArgumentNullException(nameof(sender));
}

var ei = EventInfoCache.Get((sender.GetType(), propertyName));

if (ei is null)
{
throw new InvalidOperationException("Could not find a valid event for expression.");
}

var ei = EventInfoCache.Get((sender.GetType(), propertyName)) ?? throw new InvalidOperationException("Could not find a valid event for expression.");
return Observable.Create<IObservedChange<object, object?>>(subj =>
{
var completed = false;
Expand All @@ -80,4 +74,4 @@ public int GetAffinityForObject(Type type, string propertyName, bool beforeChang
return Disposable.Create(() => ei.RemoveEventHandler(sender, handler));
});
}
}
}

0 comments on commit 9d73fba

Please sign in to comment.