Skip to content

Commit

Permalink
housekeeping: update to use modern language (#978)
Browse files Browse the repository at this point in the history
* housekeeping: Fix tests and formatting

* housekeeping: Update to modern c# 10 style
  • Loading branch information
glennawatson authored Dec 7, 2022
1 parent 941fc00 commit e8cba17
Show file tree
Hide file tree
Showing 113 changed files with 1,164 additions and 3,179 deletions.
11 changes: 4 additions & 7 deletions src/ReactiveUI.DI.Tests/Mocks/ActivatingView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,25 @@ namespace ReactiveUI.DI.Tests.Mocks;
/// <seealso cref="ReactiveUI.IActivatableView" />
public sealed class ActivatingView : ReactiveObject, IViewFor<ActivatingViewModel>, IDisposable
{
private int _count;
private ActivatingViewModel? _viewModel;

/// <summary>
/// Initializes a new instance of the <see cref="ActivatingView"/> class.
/// </summary>
public ActivatingView()
{
public ActivatingView() =>
this.WhenActivated(d =>
{
_count++;
d(Disposable.Create(() => _count--));
IsActiveCount++;
d(Disposable.Create(() => IsActiveCount--));
});
}

/// <summary>
/// Gets the count.
/// </summary>
/// <value>
/// The count.
/// </value>
public int IsActiveCount => _count;
public int IsActiveCount { get; private set; }

/// <summary>
/// Gets the loaded.
Expand Down
6 changes: 3 additions & 3 deletions src/ReactiveUI.DI.Tests/Mocks/ActivatingViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class ActivatingViewModel : ReactiveObject, IActivatableViewModel
/// </summary>
public ActivatingViewModel()
{
Activator = new ViewModelActivator();
Activator = new();

this.WhenActivated(d =>
{
Expand All @@ -28,9 +28,9 @@ public ActivatingViewModel()
}

/// <summary>
/// Gets or sets the Activator which will be used by the View when Activation/Deactivation occurs.
/// Gets the Activator which will be used by the View when Activation/Deactivation occurs.
/// </summary>
public ViewModelActivator Activator { get; protected set; }
public ViewModelActivator Activator { get; }

/// <summary>
/// Gets or sets the active count.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ public sealed class ViewWithViewContractThatShouldNotLoad : IViewFor<ViewModelOn
/// <summary>
/// Initializes a new instance of the <see cref="ViewWithViewContractThatShouldNotLoad"/> class.
/// </summary>
public ViewWithViewContractThatShouldNotLoad()
{
throw new InvalidOperationException("This view should not be created.");
}
public ViewWithViewContractThatShouldNotLoad() => throw new InvalidOperationException("This view should not be created.");

/// <inheritdoc />
object? IViewFor.ViewModel
Expand Down
10 changes: 2 additions & 8 deletions src/Splat.AppCenter/AppCenterFeatureUsageTrackingSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,10 @@ internal AppCenterFeatureUsageTrackingSession(string featureName, Guid parentRef
public Guid ParentReference { get; }

/// <inheritdoc />
public void Dispose()
{
TrackEvent("Feature Usage End");
}
public void Dispose() => TrackEvent("Feature Usage End");

/// <inheritdoc />
public IFeatureUsageTrackingSession SubFeature(string description)
{
return new AppCenterFeatureUsageTrackingSession(description, FeatureReference);
}
public IFeatureUsageTrackingSession SubFeature(string description) => new AppCenterFeatureUsageTrackingSession(description, FeatureReference);

/// <inheritdoc />
public void OnException(Exception exception)
Expand Down
6 changes: 2 additions & 4 deletions src/Splat.AppCenter/AppCenterViewTracking.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,9 @@ public void OnViewNavigation(string name)
Microsoft.AppCenter.Analytics.Analytics.TrackEvent("PageView", properties);
}

private static IDictionary<string, string> GetProperties(string name)
{
return new Dictionary<string, string>
private static IDictionary<string, string> GetProperties(string name) =>
new Dictionary<string, string>
{
{ "Name", name },
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,14 @@ internal ApplicationInsightsFeatureUsageTrackingSession(
public string FeatureName { get; }

/// <inheritdoc />
public void Dispose()
{
TrackEvent("Feature Usage End");
}
public void Dispose() => TrackEvent("Feature Usage End");

/// <inheritdoc />
public IFeatureUsageTrackingSession SubFeature(string description)
{
return new ApplicationInsightsFeatureUsageTrackingSession(
public IFeatureUsageTrackingSession SubFeature(string description) =>
new ApplicationInsightsFeatureUsageTrackingSession(
description,
FeatureReference,
_telemetryClient);
}

/// <inheritdoc />
public void OnException(Exception exception)
Expand Down
10 changes: 2 additions & 8 deletions src/Splat.ApplicationInsights/ApplicationInsightsViewTracking.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,13 @@ public sealed class ApplicationInsightsViewTracking : IViewTracking
/// Initializes a new instance of the <see cref="ApplicationInsightsViewTracking"/> class.
/// </summary>
/// <param name="telemetryClient">The Application Insights telemetry client instance to use.</param>
public ApplicationInsightsViewTracking(TelemetryClient telemetryClient)
{
_telemetryClient = telemetryClient;
}
public ApplicationInsightsViewTracking(TelemetryClient telemetryClient) => _telemetryClient = telemetryClient;

/// <summary>
/// Track a view navigation using just a name.
/// </summary>
/// <param name="name">Name of the view.</param>
public void OnViewNavigation(string name)
{
_telemetryClient.TrackPageView(name);
}
public void OnViewNavigation(string name) => _telemetryClient.TrackPageView(name);

/// <summary>
/// Track a View Navigation with Extended Data.
Expand Down
31 changes: 9 additions & 22 deletions src/Splat.Autofac/AutofacDependencyResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,7 @@ public AutofacDependencyResolver(ContainerBuilder builder)
public virtual object? GetService(Type? serviceType, string? contract = null)
{
var isNull = serviceType is null;
if (serviceType is null)
{
serviceType = typeof(NullServiceType);
}
serviceType ??= typeof(NullServiceType);

lock (_lockObject)
{
Expand Down Expand Up @@ -93,10 +90,7 @@ public void SetLifetimeScope(ILifetimeScope lifetimeScope)
public virtual IEnumerable<object> GetServices(Type? serviceType, string? contract = null)
{
var isNull = serviceType is null;
if (serviceType is null)
{
serviceType = typeof(NullServiceType);
}
serviceType ??= typeof(NullServiceType);

lock (_lockObject)
{
Expand All @@ -105,13 +99,12 @@ public virtual IEnumerable<object> GetServices(Type? serviceType, string? contra
var enumerableType = typeof(IEnumerable<>).MakeGenericType(serviceType);
var instance = Resolve(enumerableType, contract);

if (isNull && instance is IEnumerable<NullServiceType> nullService)
{
return nullService.Select(item => item.Factory()!);
}
else if (!isNull && instance is not null)
switch (isNull)
{
return ((IEnumerable)instance).Cast<object>();
case true when instance is IEnumerable<NullServiceType> nullService:
return nullService.Select(item => item.Factory()!);
case false when instance is not null:
return ((IEnumerable)instance).Cast<object>();
}
}
finally
Expand All @@ -126,10 +119,7 @@ public virtual IEnumerable<object> GetServices(Type? serviceType, string? contra
/// <inheritdoc />
public bool HasRegistration(Type? serviceType, string? contract = null)
{
if (serviceType is null)
{
serviceType = typeof(NullServiceType);
}
serviceType ??= typeof(NullServiceType);

lock (_lockObject)
{
Expand Down Expand Up @@ -158,10 +148,7 @@ public bool HasRegistration(Type? serviceType, string? contract = null)
public virtual void Register(Func<object?> factory, Type? serviceType, string? contract = null)
{
var isNull = serviceType is null;
if (serviceType is null)
{
serviceType = typeof(NullServiceType);
}
serviceType ??= typeof(NullServiceType);

lock (_lockObject)
{
Expand Down
5 changes: 1 addition & 4 deletions src/Splat.Common.Test/ViewThatShouldNotLoad.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ public sealed class ViewThatShouldNotLoad : IViewFor<ViewModelOne>
/// <summary>
/// Initializes a new instance of the <see cref="ViewThatShouldNotLoad"/> class.
/// </summary>
public ViewThatShouldNotLoad()
{
throw new InvalidOperationException("This view should not be created.");
}
public ViewThatShouldNotLoad() => throw new InvalidOperationException("This view should not be created.");

/// <inheritdoc />
object? IViewFor.ViewModel
Expand Down
15 changes: 3 additions & 12 deletions src/Splat.Drawing.Tests/BitmapLoaderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,20 +79,11 @@ public void Load_Succeeds(Func<Stream> getStream)
}
}

private static Stream GetBitmapStream()
{
return GetStream("splatlogo.bmp");
}
private static Stream GetBitmapStream() => GetStream("splatlogo.bmp");

private static Stream GetJpegStream()
{
return GetStream("splatlogo.jpg");
}
private static Stream GetJpegStream() => GetStream("splatlogo.jpg");

private static Stream GetPngStream()
{
return GetStream("splatlogo.png");
}
private static Stream GetPngStream() => GetStream("splatlogo.png");

private static Stream GetStream(string imageName)
{
Expand Down
20 changes: 4 additions & 16 deletions src/Splat.Drawing.Tests/Colors/CoverageColorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,35 +190,23 @@ public void ARGBColorToStringGivesValue()
/// Invalids the ARGB color A throws.
/// </summary>
[Fact]
public void InvalidARGBColorAThrows()
{
Assert.Throws<ArgumentException>(() => SplatColor.FromArgb(256, 0, 0, 0));
}
public void InvalidARGBColorAThrows() => Assert.Throws<ArgumentException>(() => SplatColor.FromArgb(256, 0, 0, 0));

/// <summary>
/// Invalids the ARGB color r throws.
/// </summary>
[Fact]
public void InvalidARGBColorRThrows()
{
Assert.Throws<ArgumentException>(() => SplatColor.FromArgb(0, 256, 0, 0));
}
public void InvalidARGBColorRThrows() => Assert.Throws<ArgumentException>(() => SplatColor.FromArgb(0, 256, 0, 0));

/// <summary>
/// Invalids the ARGB color g throws.
/// </summary>
[Fact]
public void InvalidARGBColorGThrows()
{
Assert.Throws<ArgumentException>(() => SplatColor.FromArgb(0, 0, 256, 0));
}
public void InvalidARGBColorGThrows() => Assert.Throws<ArgumentException>(() => SplatColor.FromArgb(0, 0, 256, 0));

/// <summary>
/// Invalids the ARGB color b throws.
/// </summary>
[Fact]
public void InvalidARGBColorBThrows()
{
Assert.Throws<ArgumentException>(() => SplatColor.FromArgb(0, 0, 0, 256));
}
public void InvalidARGBColorBThrows() => Assert.Throws<ArgumentException>(() => SplatColor.FromArgb(0, 0, 0, 256));
}
5 changes: 1 addition & 4 deletions src/Splat.Drawing.Tests/Colors/SplatColorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,7 @@ private static IEnumerable<object[]> GetEnumAsTestTheory()
{
var values = Enum.GetValues(typeof(KnownColor));
var results = new List<object[]>(values.Length);
foreach (var value in values)
{
results.Add(new[] { value! });
}
results.AddRange(values.Cast<object?>().Select(value => new[] { value! }));

return results;
}
Expand Down
Loading

0 comments on commit e8cba17

Please sign in to comment.