Skip to content

Commit e7acd48

Browse files
authored
Merge pull request #909 from CommunityToolkit/dev/winrt-aot
Add AOT support in WinRT scenarios to the MVVM Toolkit
2 parents 5c6fe61 + 488f7a7 commit e7acd48

11 files changed

+40
-11
lines changed

src/CommunityToolkit.Mvvm/Collections/ObservableGroupedCollection{TKey,TElement}.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace CommunityToolkit.Mvvm.Collections;
1515
/// </summary>
1616
/// <typeparam name="TKey">The type of the group keys.</typeparam>
1717
/// <typeparam name="TElement">The type of elements in the collection.</typeparam>
18-
public sealed class ObservableGroupedCollection<TKey, TElement> : ObservableCollection<ObservableGroup<TKey, TElement>>, ILookup<TKey, TElement>
18+
public sealed partial class ObservableGroupedCollection<TKey, TElement> : ObservableCollection<ObservableGroup<TKey, TElement>>, ILookup<TKey, TElement>
1919
where TKey : notnull
2020
{
2121
/// <summary>

src/CommunityToolkit.Mvvm/Collections/ReadOnlyObservableGroupedCollection{TKey,TElement}.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace CommunityToolkit.Mvvm.Collections;
1717
/// </summary>
1818
/// <typeparam name="TKey">The type of the group keys.</typeparam>
1919
/// <typeparam name="TElement">The type of elements in the collection.</typeparam>
20-
public sealed class ReadOnlyObservableGroupedCollection<TKey, TElement> : ReadOnlyObservableCollection<ReadOnlyObservableGroup<TKey, TElement>>, ILookup<TKey, TElement>
20+
public sealed partial class ReadOnlyObservableGroupedCollection<TKey, TElement> : ReadOnlyObservableCollection<ReadOnlyObservableGroup<TKey, TElement>>, ILookup<TKey, TElement>
2121
where TKey : notnull
2222
{
2323
/// <summary>

src/CommunityToolkit.Mvvm/CommunityToolkit.Mvvm.csproj

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,24 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>netstandard2.0;netstandard2.1;net6.0;net8.0</TargetFrameworks>
4+
<TargetFrameworks>netstandard2.0;netstandard2.1;net6.0;net8.0;net8.0-windows10.0.17763.0</TargetFrameworks>
5+
</PropertyGroup>
6+
7+
<!--
8+
Windows-only properties (supporting AOT in WinRT scenarios requires actually using the Windows TFM,
9+
because we need the source generators in CsWinRT to generate the supporting interop code for AOT).
10+
-->
11+
<PropertyGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net8.0-windows10.0.17763.0'))">
12+
<WindowsSdkPackageVersion>10.0.17763.39</WindowsSdkPackageVersion>
13+
14+
<!--
15+
We're only referencing CsWinRT for the source generators, we don't need to read any WinRT metadata.
16+
CsWinRT is in projection mode by default, so we want to disable it (or it'd need the Windows SDK).
17+
-->
18+
<CsWinRTGenerateProjection>false</CsWinRTGenerateProjection>
19+
20+
<!-- Enable AOT warnings for types implementing projected WinRT interfaces mapped to built-in types (eg. 'INotifyPropertyChanged') -->
21+
<CsWinRTAotWarningLevel>2</CsWinRTAotWarningLevel>
522
</PropertyGroup>
623

724
<PropertyGroup>
@@ -34,6 +51,11 @@
3451
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="6.0.0" />
3552
</ItemGroup>
3653

54+
<!-- Reference CsWinRT when targeting Windows, to get the latest source generators -->
55+
<ItemGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net8.0-windows10.0.17763.0'))">
56+
<PackageReference Include="Microsoft.Windows.CsWinRT" Version="2.1.0-prerelease.240801.1" PrivateAssets="all" />
57+
</ItemGroup>
58+
3759
<!-- Reference the various multi-targeted versions of the source generator project (one per Roslyn version), and the code fixer -->
3860
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
3961
<ProjectReference Include="..\CommunityToolkit.Mvvm.SourceGenerators.Roslyn401\CommunityToolkit.Mvvm.SourceGenerators.Roslyn401.csproj" ReferenceOutputAssembly="false" />
@@ -87,5 +109,4 @@
87109
<None Include="..\CommunityToolkit.Mvvm.CodeFixers\bin\$(Configuration)\netstandard2.0\CommunityToolkit.Mvvm.CodeFixers.dll" PackagePath="analyzers\dotnet\roslyn4.0\cs" Pack="true" Visible="false" />
88110
<None Include="..\CommunityToolkit.Mvvm.CodeFixers\bin\$(Configuration)\netstandard2.0\CommunityToolkit.Mvvm.CodeFixers.dll" PackagePath="analyzers\dotnet\roslyn4.3\cs" Pack="true" Visible="false" />
89111
</ItemGroup>
90-
91112
</Project>

src/CommunityToolkit.Mvvm/DependencyInjection/Ioc.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ namespace CommunityToolkit.Mvvm.DependencyInjection;
4141
/// Ioc.Default.GetService&lt;ILogger&gt;().Log("Hello world!");
4242
/// </code>
4343
/// </summary>
44-
public sealed class Ioc : IServiceProvider
44+
public sealed partial class Ioc : IServiceProvider
4545
{
4646
/// <summary>
4747
/// Gets the default <see cref="Ioc"/> instance.

src/CommunityToolkit.Mvvm/Input/AsyncRelayCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace CommunityToolkit.Mvvm.Input;
2020
/// action, and providing an <see cref="ExecutionTask"/> property that notifies changes when
2121
/// <see cref="ExecuteAsync"/> is invoked and when the returned <see cref="Task"/> completes.
2222
/// </summary>
23-
public sealed class AsyncRelayCommand : IAsyncRelayCommand, ICancellationAwareCommand
23+
public sealed partial class AsyncRelayCommand : IAsyncRelayCommand, ICancellationAwareCommand
2424
{
2525
/// <summary>
2626
/// The cached <see cref="PropertyChangedEventArgs"/> for <see cref="ExecutionTask"/>.

src/CommunityToolkit.Mvvm/Input/AsyncRelayCommand{T}.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ namespace CommunityToolkit.Mvvm.Input;
1818
/// A generic command that provides a more specific version of <see cref="AsyncRelayCommand"/>.
1919
/// </summary>
2020
/// <typeparam name="T">The type of parameter being passed as input to the callbacks.</typeparam>
21-
public sealed class AsyncRelayCommand<T> : IAsyncRelayCommand<T>, ICancellationAwareCommand
21+
public sealed partial class AsyncRelayCommand<T> : IAsyncRelayCommand<T>, ICancellationAwareCommand
2222
{
2323
/// <summary>
2424
/// The <see cref="Func{TResult}"/> to invoke when <see cref="Execute(T)"/> is used.

src/CommunityToolkit.Mvvm/Input/Internals/CancelCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace CommunityToolkit.Mvvm.Input.Internals;
1111
/// <summary>
1212
/// A <see cref="ICommand"/> implementation wrapping <see cref="IAsyncRelayCommand"/> to support cancellation.
1313
/// </summary>
14-
internal sealed class CancelCommand : ICommand
14+
internal sealed partial class CancelCommand : ICommand
1515
{
1616
/// <summary>
1717
/// The wrapped <see cref="IAsyncRelayCommand"/> instance.

src/CommunityToolkit.Mvvm/Input/Internals/DisabledCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace CommunityToolkit.Mvvm.Input.Internals;
1010
/// <summary>
1111
/// A reusable <see cref="ICommand"/> instance that is always disabled.
1212
/// </summary>
13-
internal sealed class DisabledCommand : ICommand
13+
internal sealed partial class DisabledCommand : ICommand
1414
{
1515
/// <inheritdoc/>
1616
public event EventHandler? CanExecuteChanged

src/CommunityToolkit.Mvvm/Input/RelayCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace CommunityToolkit.Mvvm.Input;
1616
/// method is <see langword="true"/>. This type does not allow you to accept command parameters
1717
/// in the <see cref="Execute"/> and <see cref="CanExecute"/> callback methods.
1818
/// </summary>
19-
public sealed class RelayCommand : IRelayCommand
19+
public sealed partial class RelayCommand : IRelayCommand
2020
{
2121
/// <summary>
2222
/// The <see cref="Action"/> to invoke when <see cref="Execute"/> is used.

src/CommunityToolkit.Mvvm/Input/RelayCommand{T}.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ namespace CommunityToolkit.Mvvm.Input;
1818
/// in the <see cref="Execute(T)"/> and <see cref="CanExecute(T)"/> callback methods.
1919
/// </summary>
2020
/// <typeparam name="T">The type of parameter being passed as input to the callbacks.</typeparam>
21-
public sealed class RelayCommand<T> : IRelayCommand<T>
21+
public sealed partial class RelayCommand<T> : IRelayCommand<T>
2222
{
2323
/// <summary>
2424
/// The <see cref="Action"/> to invoke when <see cref="Execute(T)"/> is used.

0 commit comments

Comments
 (0)