Skip to content

Commit 4419d33

Browse files
authored
Fix For IViewFor missing namespace (#65)
Fix For IViewFor Closes #54
1 parent c14b192 commit 4419d33

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+1770
-26
lines changed

src/Directory.Packages.props

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,22 @@
1919
<PackageVersion Include="Nerdbank.GitVersioning" Version="3.6.143" />
2020
<PackageVersion Include="stylecop.analyzers" Version="1.2.0-beta.556" />
2121
<PackageVersion Include="Roslynator.Analyzers" Version="4.12.5" />
22-
<PackageVersion Include="ReactiveUI" Version="20.1.52" />
22+
<PackageVersion Include="ReactiveUI" Version="20.1.63" />
2323
<PackageVersion Include="Microsoft.Maui.Controls" Version="$(MauiVersion)" />
2424
<PackageVersion Include="Microsoft.Maui.Controls.Compatibility" Version="$(MauiVersion)" />
2525
<PackageVersion Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4" />
2626
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="$(CodeAnalysisVersion)" />
2727
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="$(CodeAnalysisVersion)" />
2828
<PackageVersion Include="PolySharp" Version="1.14.1" />
29+
30+
<PackageVersion Include="Avalonia" Version="11.1.3" />
31+
<PackageVersion Include="Avalonia.Themes.Fluent" Version="11.1.3" />
32+
<PackageVersion Include="Avalonia.Fonts.Inter" Version="11.1.3" />
33+
<PackageVersion Include="Avalonia.ReactiveUI" Version="11.1.3" />
34+
<PackageVersion Include="Avalonia.Diagnostics" Version="11.1.3" />
35+
<PackageVersion Include="Avalonia.Desktop" Version="11.1.3" />
36+
37+
<PackageVersion Include="Microsoft.Extensions.Logging.Debug" Version="8.0.0" />
38+
<PackageVersion Include="ReactiveUI.Maui" Version="20.1.63" />
2939
</ItemGroup>
3040
</Project>

src/ReactiveUI.SourceGenerators.slnx

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,25 @@
99
<File Path="Directory.Packages.props" />
1010
<File Path="stylecop.json" />
1111
</Folder>
12-
<Project Path="ReactiveUI.SourceGenerators.Execute.Maui\ReactiveUI.SourceGenerators.Execute.Maui.csproj" Type="Classic C#" />
12+
<Project Path="ReactiveUI.SourceGenerators.Execute.Maui\ReactiveUI.SourceGenerators.Execute.Maui.csproj" />
1313
<Project Path="ReactiveUI.SourceGenerators.Execute\ReactiveUI.SourceGenerators.Execute.csproj" />
1414
<Project Path="ReactiveUI.SourceGenerators\ReactiveUI.SourceGenerators.csproj" />
15+
<Folder Name="/TestApps/">
16+
<Project Path="TestApps\TestWpfApplication\TestWpfApplication.csproj" />
17+
<Project Path="D:\Projects\GitHub\ReactiveUI\ReactiveUI.SourceGenerators\src\TestApps\TestWinFormsApplication\TestWinFormsApplication.csproj" />
18+
<Project Path="D:\Projects\GitHub\ReactiveUI\ReactiveUI.SourceGenerators\src\TestApps\TestWpfApplication\TestWpfApplication.csproj" />
19+
<Project Path="TestApps\TestWinFormsApplication\TestWinFormsApplication.csproj" />
20+
<Project Path="D:\Projects\GitHub\ReactiveUI\ReactiveUI.SourceGenerators\src\TestApps\TestAvaloniaApplication\TestAvaloniaApplication.csproj" />
21+
<Project Path="TestApps\TestAvaloniaApplication\TestAvaloniaApplication.csproj" />
22+
<Project Path="TestApps\TestAvaloniaApplication.Desktop\TestAvaloniaApplication.Desktop.csproj" />
23+
<Project Path="TestApps\TestMauiApplication\TestMauiApplication.csproj">
24+
<Deploy />
25+
</Project>
26+
</Folder>
27+
<Properties Name="Visual Studio">
28+
<Property Name="OpenWith" Value="17" />
29+
</Properties>
30+
<Project Path="D:\Projects\GitHub\ReactiveUI\ReactiveUI.SourceGenerators\src\ReactiveUI.SourceGenerators.Execute.Maui\ReactiveUI.SourceGenerators.Execute.Maui.csproj" />
31+
<Project Path="D:\Projects\GitHub\ReactiveUI\ReactiveUI.SourceGenerators\src\ReactiveUI.SourceGenerators.Execute\ReactiveUI.SourceGenerators.Execute.csproj" />
32+
<Project Path="D:\Projects\GitHub\ReactiveUI\ReactiveUI.SourceGenerators\src\ReactiveUI.SourceGenerators\ReactiveUI.SourceGenerators.csproj" />
1533
</Solution>

src/ReactiveUI.SourceGenerators/IViewFor/IViewForGenerator.Execute.cs

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ internal static CompilationUnitSyntax GetIViewForWpfWinUiUno(IViewForInfo iViewF
9393
writer.WriteLine("DependencyProperty.Register(");
9494
writer.WriteLine("nameof(ViewModel),");
9595
writer.WriteLine($"typeof({iViewForInfo.ViewModelTypeName}),");
96-
writer.WriteLine($"typeof(IViewFor<{iViewForInfo.ViewModelTypeName}>),");
96+
writer.WriteLine($"typeof({iViewForInfo.ClassName}),");
9797
writer.WriteLine("new PropertyMetadata(null));");
9898
writer.WriteLine();
9999

@@ -213,6 +213,7 @@ internal static CompilationUnitSyntax GetIViewForAvalonia(IViewForInfo iViewForI
213213
[
214214
UsingDirective(ParseName("System")),
215215
UsingDirective(ParseName("ReactiveUI")),
216+
UsingDirective(ParseName("Avalonia")),
216217
UsingDirective(ParseName("Avalonia.Controls")),
217218
];
218219

@@ -258,7 +259,7 @@ internal static CompilationUnitSyntax GetIViewForAvalonia(IViewForInfo iViewForI
258259
writer.WriteLine($"public static readonly StyledProperty<{iViewForInfo.ViewModelTypeName}?> ViewModelProperty =");
259260
writer.Indent++;
260261
writer.WriteLine("AvaloniaProperty");
261-
writer.WriteLine($".Register<IViewFor<{iViewForInfo.ViewModelTypeName}>, {iViewForInfo.ViewModelTypeName}?>(nameof(ViewModel));");
262+
writer.WriteLine($".Register<{iViewForInfo.ClassName}, {iViewForInfo.ViewModelTypeName}?>(nameof(ViewModel));");
262263

263264
writer.Indent--;
264265
writer.WriteLine("/// <summary>");
@@ -286,28 +287,31 @@ internal static CompilationUnitSyntax GetIViewForAvalonia(IViewForInfo iViewForI
286287
writer.Indent--;
287288
writer.WriteLine(Token(SyntaxKind.CloseBraceToken));
288289
writer.WriteLine();
289-
writer.WriteLine(@"
290-
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
291-
{
292-
base.OnPropertyChanged(change);
293-
294-
if (change.Property == DataContextProperty)
295-
{
296-
if (ReferenceEquals(change.OldValue, ViewModel)
297-
&& change.NewValue is null or TViewModel)
298-
{
299-
SetCurrentValue(ViewModelProperty, change.NewValue);
300-
}
301-
}
302-
else if (change.Property == ViewModelProperty)
303-
{
304-
if (ReferenceEquals(change.OldValue, DataContext))
305-
{
306-
SetCurrentValue(DataContextProperty, change.NewValue);
307-
}
308-
}
309-
}
310-
");
290+
writer.WriteLine(
291+
$$"""
292+
293+
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
294+
{
295+
base.OnPropertyChanged(change);
296+
297+
if (change.Property == DataContextProperty)
298+
{
299+
if (ReferenceEquals(change.OldValue, ViewModel)
300+
&& change.NewValue is null or {{iViewForInfo.ViewModelTypeName}})
301+
{
302+
SetCurrentValue(ViewModelProperty, change.NewValue);
303+
}
304+
}
305+
else if (change.Property == ViewModelProperty)
306+
{
307+
if (ReferenceEquals(change.OldValue, DataContext))
308+
{
309+
SetCurrentValue(DataContextProperty, change.NewValue);
310+
}
311+
}
312+
}
313+
314+
""");
311315
writer.Indent--;
312316
writer.WriteLine(Token(SyntaxKind.CloseBraceToken));
313317
writer.Indent--;
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright (c) 2024 .NET Foundation and Contributors. All rights reserved.
2+
// Licensed to the .NET Foundation under one or more agreements.
3+
// The .NET Foundation licenses this file to you under the MIT license.
4+
// See the LICENSE file in the project root for full license information.
5+
6+
using System;
7+
8+
using Avalonia;
9+
using Avalonia.ReactiveUI;
10+
11+
namespace AvaloniaApplication1.Desktop;
12+
13+
/// <summary>
14+
/// Program.
15+
/// </summary>
16+
internal static class Program
17+
{
18+
// Initialization code. Don't use any Avalonia, third-party APIs or any
19+
// SynchronizationContext-reliant code before AppMain is called: things aren't initialized
20+
// yet and stuff might break.
21+
[STAThread]
22+
public static void Main(string[] args) => BuildAvaloniaApp()
23+
.StartWithClassicDesktopLifetime(args);
24+
25+
// Avalonia configuration, don't remove; also used by visual designer.
26+
public static AppBuilder BuildAvaloniaApp()
27+
=> AppBuilder.Configure<App>()
28+
.UsePlatformDetect()
29+
.WithInterFont()
30+
.LogToTrace()
31+
.UseReactiveUI();
32+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<OutputType>WinExe</OutputType>
4+
<!--If you are willing to use Windows/MacOS native APIs you will need to create 3 projects.
5+
One for Windows with net8.0-windows TFM, one for MacOS with net8.0-macos and one with net8.0 TFM for Linux.-->
6+
<TargetFramework>net8.0</TargetFramework>
7+
<Nullable>enable</Nullable>
8+
<BuiltInComInteropSupport>true</BuiltInComInteropSupport>
9+
<ApplicationManifest>app.manifest</ApplicationManifest>
10+
<IsPackable>false</IsPackable>
11+
</PropertyGroup>
12+
13+
<ItemGroup>
14+
<PackageReference Include="Avalonia.Desktop" />
15+
</ItemGroup>
16+
17+
<ItemGroup>
18+
<ProjectReference Include="..\TestAvaloniaApplication\TestAvaloniaApplication.csproj" />
19+
</ItemGroup>
20+
</Project>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
3+
<!-- This manifest is used on Windows only.
4+
Don't remove it as it might cause problems with window transparency and embeded controls.
5+
For more details visit https://learn.microsoft.com/en-us/windows/win32/sbscs/application-manifests -->
6+
<assemblyIdentity version="1.0.0.0" name="AvaloniaTest.Desktop"/>
7+
8+
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
9+
<application>
10+
<!-- A list of the Windows versions that this application has been tested on
11+
and is designed to work with. Uncomment the appropriate elements
12+
and Windows will automatically select the most compatible environment. -->
13+
14+
<!-- Windows 10 -->
15+
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />
16+
</application>
17+
</compatibility>
18+
</assembly>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<Application xmlns="https://github.com/avaloniaui"
2+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3+
x:Class="AvaloniaApplication1.App"
4+
RequestedThemeVariant="Default">
5+
<!-- "Default" ThemeVariant follows system theme variant. "Dark" or "Light" are other available options. -->
6+
7+
<Application.Styles>
8+
<FluentTheme />
9+
</Application.Styles>
10+
</Application>
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Copyright (c) 2024 .NET Foundation and Contributors. All rights reserved.
2+
// Licensed to the .NET Foundation under one or more agreements.
3+
// The .NET Foundation licenses this file to you under the MIT license.
4+
// See the LICENSE file in the project root for full license information.
5+
6+
using Avalonia;
7+
using Avalonia.Controls.ApplicationLifetimes;
8+
using Avalonia.Markup.Xaml;
9+
10+
using AvaloniaApplication1.ViewModels;
11+
using AvaloniaApplication1.Views;
12+
13+
namespace AvaloniaApplication1;
14+
15+
/// <summary>
16+
/// App.
17+
/// </summary>
18+
/// <seealso cref="Avalonia.Application" />
19+
public partial class App : Application
20+
{
21+
/// <summary>
22+
/// Initializes the application by loading XAML etc.
23+
/// </summary>
24+
public override void Initialize()
25+
{
26+
AvaloniaXamlLoader.Load(this);
27+
}
28+
29+
/// <summary>
30+
/// Called when [framework initialization completed].
31+
/// </summary>
32+
public override void OnFrameworkInitializationCompleted()
33+
{
34+
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
35+
{
36+
desktop.MainWindow = new MainWindow
37+
{
38+
DataContext = new MainViewModel()
39+
};
40+
}
41+
else if (ApplicationLifetime is ISingleViewApplicationLifetime singleViewPlatform)
42+
{
43+
singleViewPlatform.MainView = new MainView
44+
{
45+
DataContext = new MainViewModel()
46+
};
47+
}
48+
49+
base.OnFrameworkInitializationCompleted();
50+
}
51+
}
Binary file not shown.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<TargetFramework>net8.0</TargetFramework>
4+
<Nullable>enable</Nullable>
5+
<LangVersion>latest</LangVersion>
6+
<IsPackable>false</IsPackable>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<AvaloniaResource Include="Assets\**" />
11+
</ItemGroup>
12+
13+
<ItemGroup>
14+
<PackageReference Include="Avalonia" />
15+
<PackageReference Include="Avalonia.Themes.Fluent" />
16+
<PackageReference Include="Avalonia.Fonts.Inter" />
17+
<PackageReference Include="Avalonia.ReactiveUI" />
18+
<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
19+
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" />
20+
</ItemGroup>
21+
22+
<ItemGroup>
23+
<ProjectReference Include="..\..\ReactiveUI.SourceGenerators\ReactiveUI.SourceGenerators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
24+
</ItemGroup>
25+
</Project>

0 commit comments

Comments
 (0)