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

Update dependencies, enable C# 11 #306

Merged
merged 4 commits into from
Dec 29, 2022
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
3 changes: 1 addition & 2 deletions AmbientSounds.Tests/AmbientSounds.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>

<TargetFramework>net6.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>

Expand Down
21 changes: 21 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project>
<PropertyGroup>
<LangVersion>11.0</LangVersion>

<!--
Enable the latest warning wave, which shows additional warnings for invalid language features that are disabled by default.
For additional info, see https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/compiler-messages/warning-waves.
-->
<AnalysisLevel>7</AnalysisLevel>

<!-- Import the global configs from the CodeStyle package (enables all IDExxxx warnings)-->
<AnalysisLevelStyle>7-all</AnalysisLevelStyle>

<!--
Enable the compiler strict mode (see https://www.meziantou.net/csharp-compiler-strict-mode.htm).
This (poorly documented) mode enables additional warnings for incorrect usages of some features.
For instance, this will warn when using the == operator to compare a struct with a null literal.
-->
<Features>strict</Features>
</PropertyGroup>
</Project>
1 change: 0 additions & 1 deletion src/AmbientSounds.Uwp/AmbientSounds.Uwp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
<ProjectTypeGuids>{A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<WindowsXamlEnableOverview>true</WindowsXamlEnableOverview>
<AppxPackageSigningEnabled>false</AppxPackageSigningEnabled>
<LangVersion>10.0</LangVersion>
<UseDotNetNativeSharedAssemblyFrameworkPackage>false</UseDotNetNativeSharedAssemblyFrameworkPackage>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
Expand Down
8 changes: 5 additions & 3 deletions src/AmbientSounds.Uwp/Controls/ObservableUserControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,24 @@
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;

#nullable enable

namespace AmbientSounds.Controls
{
// Source: https://gist.github.com/dpaulino/2e988a78fee6d99198d306681b234437

public abstract class ObservableUserControl : UserControl, INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
public event PropertyChangedEventHandler? PropertyChanged;

protected void SetValueDp(DependencyProperty property, object value,
[System.Runtime.CompilerServices.CallerMemberName] string p = null)
[System.Runtime.CompilerServices.CallerMemberName] string? p = null)
{
SetValue(property, value);
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(p));
}

protected void OnPropertyChanged([System.Runtime.CompilerServices.CallerMemberName] string p = null)
protected void OnPropertyChanged([System.Runtime.CompilerServices.CallerMemberName] string? p = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(p));
}
Expand Down
5 changes: 2 additions & 3 deletions src/AmbientSounds/AmbientSounds.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>10.0</LangVersion>
<Nullable>enable</Nullable>
</PropertyGroup>

Expand Down Expand Up @@ -38,8 +37,8 @@
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="5.0.17" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
<PackageReference Include="MimeTypeMapOfficial" Version="1.0.17" />
<PackageReference Include="PolySharp" Version="1.3.0" PrivateAssets="all" />
<PackageReference Include="System.Text.Json" Version="7.0.0-rc.2.22472.3" />
<PackageReference Include="PolySharp" Version="1.8.1" PrivateAssets="all" />
<PackageReference Include="System.Text.Json" Version="7.0.1" />
</ItemGroup>

<!-- MSBuild properties to customize the generation from PolySharp -->
Expand Down
15 changes: 6 additions & 9 deletions src/AmbientSounds/Constants/IapConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,14 @@ public static (string, int) SplitIdAndVersion(this string iapId)
return (string.Empty, 0);
}

var split = iapId.Split('_');
if (split.Length <= 1)
if (iapId.Split('_') is [string id, string version, ..])
{
return (iapId, 0);
}
else
{
return int.TryParse(split[1], out int result)
? (split[0], result)
: (split[0], 0);
return int.TryParse(version, out int result)
? (id, result)
: (id, 0);
}

return (iapId, 0);
}
}
}
5 changes: 3 additions & 2 deletions src/AmbientSounds/Models/Video.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Text.Json.Serialization;
using System;
using System.Text.Json.Serialization;

namespace AmbientSounds.Models
{
Expand Down Expand Up @@ -63,6 +64,6 @@ public class Video
/// Ids used to identify the IAPs
/// associated with this video.
/// </summary>
public string[] IapIds { get; set; } = new string[0];
public string[] IapIds { get; set; } = Array.Empty<string>();
}
}
15 changes: 6 additions & 9 deletions src/AmbientSounds/ViewModels/SoundListViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,17 +184,14 @@ private void OnSoundCollectionChanged(object sender, NotifyCollectionChangedEven
{
_reorderedOldIndex = e.OldStartingIndex;
}
else if (e.Action == NotifyCollectionChangedAction.Add && !_isAdding)
else if (e is { Action: NotifyCollectionChangedAction.Add, NewItems: [SoundViewModel svm, ..] } && !_isAdding)
{
if (e.NewItems.Count > 0 && e.NewItems[0] is SoundViewModel svm)
{
_ = _soundService.UpdatePositionsAsync(
svm.Id,
_reorderedOldIndex,
e.NewStartingIndex).ConfigureAwait(false);
_ = _soundService.UpdatePositionsAsync(
svm.Id,
_reorderedOldIndex,
e.NewStartingIndex).ConfigureAwait(false);

_telemetry.TrackEvent(TelemetryConstants.SoundReordered);
}
_telemetry.TrackEvent(TelemetryConstants.SoundReordered);
}
}

Expand Down
8 changes: 6 additions & 2 deletions src/AmbientSounds/ViewModels/SoundViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ public bool PlusBadgeVisible
else
{
// backwards compatibility
#pragma warning disable CS0618
return _sound.IsPremium && _sound.IapId == IapConstants.MsStoreAmbiePlusId;
#pragma warning restore CS0618
}
}
}
Expand Down Expand Up @@ -148,11 +150,11 @@ public bool PlusBadgeVisible

public bool HasSecondImage => IsMix && _sound.ImagePaths.Length == 2;

public string? SecondImagePath => _sound.ImagePaths.Length >= 2 ? _sound.ImagePaths[1] : "http://localhost:8000";
public string? SecondImagePath => _sound.ImagePaths is [_, var path, ..] ? path : "http://localhost:8000";

public bool HasThirdImage => IsMix && _sound.ImagePaths.Length == 3;

public string? ThirdImagePath => _sound.ImagePaths.Length >= 3 ? _sound.ImagePaths[2] : "http://localhost:8000";
public string? ThirdImagePath => _sound.ImagePaths is [_, _, var path, ..] ? path : "http://localhost:8000";

/// <summary>
/// The path for the image to display for the current sound.
Expand Down Expand Up @@ -303,7 +305,9 @@ private async Task PlayAsync()

var owned = _sound.IapIds.Count > 0
? await _iapService.IsAnyOwnedAsync(_sound.IapIds)
#pragma warning disable CS0618
: await _iapService.IsOwnedAsync(_sound.IapId); // backwards compatibility
#pragma warning restore CS0618

if (!owned)
{
Expand Down