Skip to content

Commit

Permalink
Merge branch 'main' into feature/project-source-scanning
Browse files Browse the repository at this point in the history
  • Loading branch information
dpvreony committed Jun 17, 2024
2 parents ab92ef7 + ed79d7a commit 9d208d2
Show file tree
Hide file tree
Showing 32 changed files with 623 additions and 124 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
# vs where release

- name: Checkout code
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
with:
fetch-depth: 0

Expand Down Expand Up @@ -176,7 +176,7 @@ jobs:
DOTNET_GENERATE_ASPNET_CERTIFICATE: false
steps:
- name: Checkout
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
with:
fetch-depth: 0

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
with:
fetch-depth: 0

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0-windows10.0.19041</TargetFramework>
<LangVersion>9</LangVersion>
<DebugType>full</DebugType>
<DebugSymbols>True</DebugSymbols>
<!--
If you're seeing CS8032 warnings, it can be because the upstream source generator dll has been rebuilt or you've changed the
target frameworks in this project. Visual Studio seems to have a cache that invalidates. Reloading Visual Studio can
solve the issue.
-->
<!--<WarningsAsErrors>8032,8785</WarningsAsErrors>-->
<TreatWarningsAsErrors />
<IsPackable>False</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Avalonia.ReactiveUI" Version="11.0.10" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Vetuviem.Avalonia.SourceGenerator\Vetuviem.Avalonia.SourceGenerator.csproj" OutputItemType="Analyzer" />
<ProjectReference Include="..\Vetuviem.Core\Vetuviem.Core.csproj" />
</ItemGroup>

<Import Project="..\Vetuviem.SourceGenerator\Vetuviem-SourceGenerator.props" />
<PropertyGroup>
<Vetuviem_Make_Classes_Public>true</Vetuviem_Make_Classes_Public>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<ItemGroup Condition="$(UseBlazorRoslynPackageWorkaround) == 'true'">
<!-- Microsoft.CodeAnalysis.CSharp is an attempt to workaround https://github.com/dotnet/aspnetcore/issues/40333 -->
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.9.2" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.10.0" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using ReactiveUI.WPF.SampleApp.ViewModels;
using ReactiveUI.WPF.SampleApp.Views;
Expand All @@ -25,7 +26,7 @@ protected override IEnumerable<IControlBindingModel<QuestionnaireView, Questionn
// launch interaction
yield return new ButtonControlBindingModel<QuestionnaireView, QuestionnaireViewModel>(vw => vw.LaunchInteraction)
{
Command = new CommandBinding<QuestionnaireViewModel>(vm => vm.LaunchInteraction)
BindCommand = new CommandBinding<QuestionnaireViewModel>(vm => vm.LaunchInteraction)
};

// Forename
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.5.240428000" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.5.240607001" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright (c) 2022 DPVreony and Contributors. All rights reserved.
// DPVreony and Contributors licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.

using Microsoft.CodeAnalysis;
using Vetuviem.SourceGenerator;
using Vetuviem.SourceGenerator.Features.Core;

namespace Vetuviem.Avalonia.SourceGenerator
{
/// <summary>
/// Control Binding Model Source Generator for Blazor.
/// </summary>
[Generator]
public sealed class AvaloniaControlBindingModelSourceGenerator : AbstractControlBindingModelSourceGenerator
{
/// <inheritdoc />
protected override MetadataReference? CheckIfShouldAddMissingAssemblyReference(string assemblyOfInterest)
{
return null;
}

/// <inheritdoc />
protected override IPlatformResolver GetPlatformResolver()
{
return new AvaloniaPlatformResolver();
}

/// <inheritdoc />
protected override string GetPlatformName()
{
return "Avalonia";
}
}
}
43 changes: 43 additions & 0 deletions src/Vetuviem.Avalonia.SourceGenerator/AvaloniaPlatformResolver.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright (c) 2022 DPVreony and Contributors. All rights reserved.
// DPVreony and Contributors licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.

using Vetuviem.SourceGenerator.Features.Core;

namespace Vetuviem.Avalonia.SourceGenerator
{
/// <summary>
/// UI Platform resolver for Blazor.
/// </summary>
public sealed class AvaloniaPlatformResolver : IPlatformResolver
{
/// <inheritdoc />
public string[] GetAssemblyNames()
{
return new[]
{
"Avalonia.Base.dll",
"Avalonia.Controls.dll",
"Avalonia.ReactiveUI.dll"
};
}

/// <inheritdoc />
public string GetBaseUiElement()
{
return "global::Avalonia.Visual";
}

/// <inheritdoc />
public string? GetCommandSourceInterface()
{
return "global::Avalonia.Input.ICommandSource";
}

/// <inheritdoc />
public string GetCommandInterface()
{
return "global::Avalonia.Input.ICommand";
}
}
}
6 changes: 6 additions & 0 deletions src/Vetuviem.Blazor.SourceGenerator/BlazorPlatformResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ public string GetBaseUiElement()
return "global::Microsoft.AspNetCore.Components.IComponent";
}

/// <inheritdoc />
public string? GetCommandSourceInterface()
{
return null;
}

/// <inheritdoc />
public string? GetCommandInterface()
{
Expand Down
15 changes: 7 additions & 8 deletions src/Vetuviem.Core/CommandBinding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

using System;
using System.Linq.Expressions;
using System.Reactive;
using System.Reactive.Disposables;
using System.Windows.Input;
using ReactiveUI;
Expand All @@ -15,10 +14,10 @@ namespace Vetuviem.Core
/// Represents a command binding between a control and a viewmodel.
/// </summary>
/// <typeparam name="TViewModel">The type for the viewmodel.</typeparam>
public sealed class CommandBinding<TViewModel> : ICommandBinding<TViewModel, ICommand>
public sealed class CommandBinding<TViewModel> : ICommandBinding<TViewModel>
where TViewModel : class
{
private readonly Expression<Func<TViewModel, ReactiveCommand<Unit, Unit>?>> _viewModelBinding;
private readonly Expression<Func<TViewModel, ICommand?>> _viewModelBinding;
private readonly string? _toEvent;

/// <summary>
Expand All @@ -27,19 +26,19 @@ public sealed class CommandBinding<TViewModel> : ICommandBinding<TViewModel, ICo
/// <param name="viewModelBinding">Expression for the View Model binding.</param>
/// <param name="toEvent">If specified, bind to the specific event instead of the default.</param>
public CommandBinding(
Expression<Func<TViewModel, ReactiveCommand<Unit, Unit>?>> viewModelBinding,
Expression<Func<TViewModel, ICommand?>> viewModelBinding,
string? toEvent = null)
{
_viewModelBinding = viewModelBinding;
_toEvent = toEvent;
}

/// <inheritdoc/>
public void ApplyBinding<TView>(
public void ApplyBinding<TView, TViewProp>(
Action<IDisposable> disposeAction,
TView view,
TViewModel viewModel,
Expression<Func<TView, ICommand>> viewBinding)
Expression<Func<TView, TViewProp>> viewBinding)
where TView : class, IViewFor<TViewModel>
{
if (disposeAction == null)
Expand Down Expand Up @@ -70,11 +69,11 @@ public void ApplyBinding<TView>(
}

/// <inheritdoc/>
public void ApplyBinding<TView>(
public void ApplyBinding<TView, TViewProp>(
CompositeDisposable compositeDisposable,
TView view,
TViewModel viewModel,
Expression<Func<TView, ICommand>> viewBinding)
Expression<Func<TView, TViewProp>> viewBinding)
where TView : class, IViewFor<TViewModel>
{
if (compositeDisposable == null)
Expand Down
9 changes: 5 additions & 4 deletions src/Vetuviem.Core/ICommandBinding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@ namespace Vetuviem.Core
/// Represents a View to View Model Binding for Commands.
/// </summary>
/// <typeparam name="TViewModel">The type for the ViewModel.</typeparam>
/// <typeparam name="TViewProp">The type for the View.</typeparam>
public interface ICommandBinding<TViewModel, TViewProp>
public interface ICommandBinding<TViewModel>
where TViewModel : class
{
/// <summary>
/// Applies a View to View Model Binding.
/// </summary>
/// <typeparam name="TView">The type for the view.</typeparam>
/// <typeparam name="TViewProp">The type for the View Property.</typeparam>
/// <param name="d">The disposable action registration. Used to clean up when bindings fall out of scope.</param>
/// <param name="view">The instance of the View to bind.</param>
/// <param name="viewModel">The instance of the ViewModel to Bind.</param>
/// <param name="viewBinding">Expression of the View Property to Bind to.</param>
void ApplyBinding<TView>(
void ApplyBinding<TView, TViewProp>(
Action<IDisposable> d,
TView view,
TViewModel viewModel,
Expand All @@ -36,11 +36,12 @@ void ApplyBinding<TView>(
/// Applies a View to View Model Binding.
/// </summary>
/// <typeparam name="TView">The type for the view.</typeparam>
/// <typeparam name="TViewProp">The type for the View Property.</typeparam>
/// <param name="compositeDisposable">The disposable action registration. Used to clean up when bindings fall out of scope.</param>
/// <param name="view">The instance of the View to bind.</param>
/// <param name="viewModel">The instance of the ViewModel to Bind.</param>
/// <param name="viewBinding">Expression of the View Property to Bind to.</param>
void ApplyBinding<TView>(
void ApplyBinding<TView, TViewProp>(
CompositeDisposable compositeDisposable,
TView view,
TViewModel viewModel,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// Copyright (c) 2022 DPVreony and Contributors. All rights reserved.
// DPVreony and Contributors licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.

using System;
using System.Collections.Generic;
using System.IO;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Diagnostics;
using Vetuviem.Avalonia.SourceGenerator;
using Vetuviem.SourceGenerator.Features.ControlBindingModels;
using Vetuviem.Testing;
using Vetuviem.Winforms.SourceGenerator;
using Xunit.Abstractions;

namespace Vetuviem.IntegrationTests.ReactiveUI.Avalonia
{
/// <summary>
/// Unit Tests for the ViewBinding Model Source Generator.
/// </summary>
public static class AvaloniaViewBindingModelGeneratorTests
{
/// <inheritdoc />
public sealed class ExecuteMethod : BaseGeneratorTests.BaseExecuteMethod<AvaloniaControlBindingModelSourceGenerator, ControlBindingModelGeneratorProcessor>
{
/// <summary>
/// Initializes a new instance of the <see cref="ExecuteMethod"/> class.
/// </summary>
/// <param name="output">Test Output Helper.</param>
public ExecuteMethod(ITestOutputHelper output)
: base(output)
{
}

/// <inheritdoc />
protected override AnalyzerConfigOptionsProvider? GetAnalyzerConfigOptionsProvider()
{
return null;
}

/// <inheritdoc />
protected override void AddReferenceAssemblies(IList<MetadataReference> metadataReferences)
{
if (metadataReferences == null)
{
throw new ArgumentNullException(nameof(metadataReferences));
}

var trustedAssembliesPaths = GetPlatformAssemblyPaths();
if (trustedAssembliesPaths == null)
{
return;
}

foreach (string trustedAssembliesPath in trustedAssembliesPaths)
{
var metadataReference = MetadataReference.CreateFromFile(trustedAssembliesPath);
metadataReferences.Add(metadataReference);
}
}

/// <inheritdoc />
protected override Func<AvaloniaControlBindingModelSourceGenerator> GetFactory()
{
return () => new AvaloniaControlBindingModelSourceGenerator();
}

private static string[]? GetPlatformAssemblyPaths()
{
if (AppContext.GetData("TRUSTED_PLATFORM_ASSEMBLIES") is string trustedPlatformAssemblies)
{
return trustedPlatformAssemblies.Split(Path.PathSeparator);
}

return null;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2022 DPVreony and Contributors. All rights reserved.
// Copyright (c) 2022 DPVreony and Contributors. All rights reserved.
// DPVreony and Contributors licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2022 DPVreony and Contributors. All rights reserved.
// Copyright (c) 2022 DPVreony and Contributors. All rights reserved.
// DPVreony and Contributors licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Avalonia.ReactiveUI" Version="11.0.10" />
<PackageReference Include="MahApps.Metro" Version="2.4.10" />
<PackageReference Include="MahApps.Metro.SimpleChildWindow" Version="2.2.1" />
<PackageReference Include="ReactiveUI.WPF" Version="20.1.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Vetuviem.Avalonia.SourceGenerator\Vetuviem.Avalonia.SourceGenerator.csproj" />
<ProjectReference Include="..\Vetuviem.Maui.SourceGenerator\Vetuviem.Maui.SourceGenerator.csproj" />
<ProjectReference Include="..\Vetuviem.Testing\Vetuviem.Testing.csproj" />
<ProjectReference Include="..\Vetuviem.Winforms.SourceGenerator\Vetuviem.Winforms.SourceGenerator.csproj" />
<ProjectReference Include="..\Vetuviem.WinUi.SourceGenerator\Vetuviem.WinUi.SourceGenerator.csproj" />
Expand Down
Loading

0 comments on commit 9d208d2

Please sign in to comment.