Skip to content

Commit 4ff0317

Browse files
committed
Bump to C# 10, minor code tweaks
1 parent a7bb358 commit 4ff0317

File tree

7 files changed

+17
-13
lines changed

7 files changed

+17
-13
lines changed

samples/Directory.Build.props

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<Project>
2+
<PropertyGroup>
3+
<LangVersion>10.0</LangVersion>
4+
<Nullable>enable</Nullable>
5+
</PropertyGroup>
6+
</Project>

samples/MvvmSample.Core/Docs/PuttingThingsTogether.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,6 @@ public interface ISettingsService
178178
/// </summary>
179179
/// <typeparam name="T">The type of the object to retrieve.</typeparam>
180180
/// <param name="key">The key associated to the requested object.</param>
181-
[Pure]
182181
T GetValue<T>(string key);
183182
}
184183
```

samples/MvvmSample.Core/MvvmSample.Core.csproj

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
<PropertyGroup>
44
<TargetFramework>netstandard2.0</TargetFramework>
5-
<LangVersion>9.0</LangVersion>
6-
<Nullable>enable</Nullable>
75
<UserSecretsId>4e66f7b4-01a8-4f00-8733-4ae6a08c741f</UserSecretsId>
86
</PropertyGroup>
97

samples/MvvmSample.Core/Services/ISettingsService.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// See the LICENSE file in the project root for more information.
44

55
using System;
6-
using System.Diagnostics.Contracts;
76

87
namespace MvvmSample.Core.Services
98
{
@@ -18,14 +17,13 @@ public interface ISettingsService
1817
/// <typeparam name="T">The type of the object bound to the key.</typeparam>
1918
/// <param name="key">The key to check.</param>
2019
/// <param name="value">The value to assign to the setting key.</param>
21-
void SetValue<T>(string key, T value);
20+
void SetValue<T>(string key, T? value);
2221

2322
/// <summary>
2423
/// Reads a value from the current <see cref="IServiceProvider"/> instance and returns its casting in the right type.
2524
/// </summary>
2625
/// <typeparam name="T">The type of the object to retrieve.</typeparam>
2726
/// <param name="key">The key associated to the requested object.</param>
28-
[Pure]
2927
T? GetValue<T>(string key);
3028
}
3129
}

samples/MvvmSampleUwp/Converters/TaskResultConverter.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
using System.Threading.Tasks;
77
using Windows.UI.Xaml.Data;
88

9+
#nullable enable
10+
911
namespace Microsoft.Toolkit.Uwp.UI.Converters
1012
{
1113
/// <summary>
@@ -15,7 +17,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Converters
1517
public sealed class TaskResultConverter2 : IValueConverter
1618
{
1719
/// <inheritdoc/>
18-
public object Convert(object value, Type targetType, object parameter, string language)
20+
public object? Convert(object? value, Type? targetType, object? parameter, string? language)
1921
{
2022
if (value is Task task)
2123
{
@@ -26,7 +28,7 @@ public object Convert(object value, Type targetType, object parameter, string la
2628
}
2729

2830
/// <inheritdoc/>
29-
public object ConvertBack(object value, Type targetType, object parameter, string language)
31+
public object ConvertBack(object? value, Type? targetType, object? parameter, string? language)
3032
{
3133
throw new NotImplementedException();
3234
}

samples/MvvmSampleUwp/MvvmSampleUwp.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
<ProjectTypeGuids>{A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
1919
<WindowsXamlEnableOverview>true</WindowsXamlEnableOverview>
2020
<AppxPackageSigningEnabled>false</AppxPackageSigningEnabled>
21-
<LangVersion>9.0</LangVersion>
2221
</PropertyGroup>
2322
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
2423
<DebugSymbols>true</DebugSymbols>

samples/MvvmSampleUwp/Services/SettingsService.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
using Windows.Foundation.Collections;
77
using Windows.Storage;
88

9+
#nullable enable
10+
911
namespace MvvmSampleUwp.Services
1012
{
1113
/// <summary>
@@ -19,18 +21,18 @@ public sealed class SettingsService : ISettingsService
1921
private readonly IPropertySet SettingsStorage = ApplicationData.Current.LocalSettings.Values;
2022

2123
/// <inheritdoc/>
22-
public void SetValue<T>(string key, T value)
24+
public void SetValue<T>(string key, T? value)
2325
{
2426
if (!SettingsStorage.ContainsKey(key)) SettingsStorage.Add(key, value);
2527
else SettingsStorage[key] = value;
2628
}
2729

2830
/// <inheritdoc/>
29-
public T GetValue<T>(string key)
31+
public T? GetValue<T>(string key)
3032
{
31-
if (SettingsStorage.TryGetValue(key, out object value))
33+
if (SettingsStorage.TryGetValue(key, out object? value))
3234
{
33-
return (T)value;
35+
return (T)value!;
3436
}
3537

3638
return default;

0 commit comments

Comments
 (0)