Skip to content
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ This documentation covers using ReactiveUI Source Generators to simplify and enh

ReactiveUI Source Generators automatically generate ReactiveUI objects to streamline your code. These Source Generators are designed to work with ReactiveUI V19.5.31+ and support the following features:

- `[Reactive]` With field and access modifiers, partial property support (C# 13 Visual Studio Version 17.12.0), partial properties with initializer support (C# preview only)
- `[Reactive]` With field and access modifiers, partial property support (C# 13 Visual Studio Version 17.12.0), partial properties with initializer support (C# 14+/preview only)
- `[Reactive(SetModifier = AccessModifier.Protected)]` With field and access modifiers, (Not Required for partial properties, configure set accessor with the property declaration).
- `[Reactive(Inheritance = InheritanceModifier.Virtual)]` With field and access modifiers. This will generate a virtual property.
- `[Reactive(UseRequired = true)]` With field and access modifiers. This will generate a required property, (Not Required for partial properties, use required keyword for property declaration).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ internal sealed class ReactiveCommandAttribute : global::System.Attribute
/// <value>
/// The reactive attribute.
/// </value>
#if ROSYLN_412
#if ROSYLN_412 || ROSYLN_500
public static string ReactiveAttribute => $$"""
// Copyright (c) {{DateTime.Now.Year}} .NET Foundation and Contributors. All rights reserved.
// Licensed to the .NET Foundation under one or more agreements.
Expand Down Expand Up @@ -275,7 +275,7 @@ public ReactiveAttribute(params string[] alsoNotify)
#endif

public const string ObservableAsPropertyAttributeType = "ReactiveUI.SourceGenerators.ObservableAsPropertyAttribute";
#if ROSYLN_412
#if ROSYLN_412 || ROSYLN_500
public static string ObservableAsPropertyAttribute => $$"""
// Copyright (c) {{DateTime.Now.Year}} .NET Foundation and Contributors. All rights reserved.
// Licensed to the .NET Foundation under one or more agreements.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public sealed partial class ObservableAsPropertyGenerator

isNullableType = propertySymbol.Type is INamedTypeSymbol nullcheck && nullcheck.TypeArguments[0].IsNullableType();
}
#if ROSYLN_412
#if ROSYLN_412 || ROSYLN_500
else
{
if (!propertySymbol.IsPartialDefinition || propertySymbol.IsStatic)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public sealed partial class ReactiveGenerator
internal static readonly string GeneratorName = typeof(ReactiveGenerator).FullName!;
internal static readonly string GeneratorVersion = typeof(ReactiveGenerator).Assembly.GetName().Version.ToString();

#if ROSYLN_412
#if ROSYLN_412 || ROSYLN_500
private static Result<PropertyInfo?>? GetPropertyInfo(in GeneratorAttributeSyntaxContext context, CancellationToken token)
{
using var builder = ImmutableArrayBuilder<DiagnosticInfo>.Rent();
Expand Down Expand Up @@ -123,11 +123,17 @@ public sealed partial class ReactiveGenerator

var typeNameWithNullabilityAnnotations = propertySymbol.Type.GetFullyQualifiedNameWithNullabilityAnnotations();
var fieldName = propertySymbol.GetGeneratedFieldName();

#if ROSYLN_500
if (context.SemanticModel.Compilation is CSharpCompilation compilation && compilation.LanguageVersion >= LanguageVersion.CSharp14)
{
fieldName = "field";
}
#else
if (context.SemanticModel.Compilation is CSharpCompilation compilation && compilation.LanguageVersion == LanguageVersion.Preview)
{
fieldName = "field";
}
#endif

var propertyName = propertySymbol.Name;

Expand Down Expand Up @@ -176,14 +182,14 @@ public sealed partial class ReactiveGenerator
}
#endif

/// <summary>
/// Gets the observable method information.
/// </summary>
/// <param name="context">The context.</param>
/// <param name="token">The token.</param>
/// <returns>
/// The value.
/// </returns>
/// <summary>
/// Gets the observable method information.
/// </summary>
/// <param name="context">The context.</param>
/// <param name="token">The token.</param>
/// <returns>
/// The value.
/// </returns>
private static Result<PropertyInfo?>? GetVariableInfo(in GeneratorAttributeSyntaxContext context, CancellationToken token)
{
using var builder = ImmutableArrayBuilder<DiagnosticInfo>.Rent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
});

RunReactiveFromField(context);
#if ROSYLN_412
#if ROSYLN_412 || ROSYLN_500
RunReactiveFromProperty(context);
#endif
}
Expand Down Expand Up @@ -87,7 +87,7 @@ private static void RunReactiveFromField(IncrementalGeneratorInitializationConte
});
}

#if ROSYLN_412
#if ROSYLN_412 || ROSYLN_500
private static void RunReactiveFromProperty(IncrementalGeneratorInitializationContext context)
{
// Gather info for all annotated variable with at least one attribute.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>$(RoslynTfm)</TargetFramework>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<IsRoslynComponent>true</IsRoslynComponent>
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<IncludeBuildOutput>false</IncludeBuildOutput>
<DevelopmentDependency>true</DevelopmentDependency>
<IsPackable>false</IsPackable>

<PackageDescription>A MVVM framework that integrates with the Reactive Extensions for .NET to create elegant, testable User Interfaces that run on any mobile or desktop platform. This is the Source Generators package for ReactiveUI</PackageDescription>
<AssemblyName>ReactiveUI.SourceGenerators</AssemblyName>
<DefineConstants>$(DefineConstants);ROSYLN_500</DefineConstants>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" PrivateAssets="all" VersionOverride="5.0.0" />
<PackageReference Include="Microsoft.CodeAnalysis.Common" PrivateAssets="all" VersionOverride="5.0.0" />
<PackageReference Include="Microsoft.CodeAnalysis.Workspaces.Common" PrivateAssets="all" VersionOverride="5.0.0" />
<PackageReference Include="Microsoft.CodeAnalysis" PrivateAssets="all" VersionOverride="5.0.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" PrivateAssets="all" VersionOverride="5.0.0" />
</ItemGroup>

<ItemGroup>
<InternalsVisibleTo Include="ReactiveUI.CodeFixes" />
</ItemGroup>

<ItemGroup>
<Compile Include="..\ReactiveUI.SourceGenerators.Roslyn\**\*.cs" LinkBase="Shared" />
</ItemGroup>

<ItemGroup>
<AdditionalFiles Include="..\ReactiveUI.SourceGenerators.Roslyn\AnalyzerReleases.Shipped.md" />
<AdditionalFiles Include="..\ReactiveUI.SourceGenerators.Roslyn\AnalyzerReleases.Unshipped.md" />
</ItemGroup>

</Project>
10 changes: 8 additions & 2 deletions src/ReactiveUI.SourceGenerators.sln
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.10.35027.167
# Visual Studio Version 18
VisualStudioVersion = 18.1.11312.151 d18.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SolutionConfig", "SolutionConfig", "{F29AF2F3-DEC8-58BC-043A-1447862C832D}"
ProjectSection(SolutionItems) = preProject
Expand Down Expand Up @@ -38,6 +38,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ReactiveUI.SourceGenerators
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ReactiveUI.SourceGenerators.Roslyn4120", "ReactiveUI.SourceGenerators.Roslyn4120\ReactiveUI.SourceGenerators.Roslyn4120.csproj", "{BF121262-7F30-4EC0-9F03-324AC3B834B8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ReactiveUI.SourceGenerators.Roslyn5000", "ReactiveUI.SourceGenerators.Roslyn5000\ReactiveUI.SourceGenerators.Roslyn5000.csproj", "{93D7DF9A-791F-4DCF-ADBA-95BFAF3E98A7}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -84,6 +86,10 @@ Global
{BF121262-7F30-4EC0-9F03-324AC3B834B8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BF121262-7F30-4EC0-9F03-324AC3B834B8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BF121262-7F30-4EC0-9F03-324AC3B834B8}.Release|Any CPU.Build.0 = Release|Any CPU
{93D7DF9A-791F-4DCF-ADBA-95BFAF3E98A7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{93D7DF9A-791F-4DCF-ADBA-95BFAF3E98A7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{93D7DF9A-791F-4DCF-ADBA-95BFAF3E98A7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{93D7DF9A-791F-4DCF-ADBA-95BFAF3E98A7}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

<ItemGroup>
<ProjectReference Include="..\ReactiveUI.SourceGenerators.Analyzers.CodeFixes\ReactiveUI.SourceGenerators.Analyzers.CodeFixes.csproj" />
<ProjectReference Include="..\ReactiveUI.SourceGenerators.Roslyn5000\ReactiveUI.SourceGenerators.Roslyn5000.csproj" ReferenceOutputAssembly="false" />
<ProjectReference Include="..\ReactiveUI.SourceGenerators.Roslyn4120\ReactiveUI.SourceGenerators.Roslyn4120.csproj" ReferenceOutputAssembly="false" />
<ProjectReference Include="..\ReactiveUI.SourceGenerators.Roslyn480\ReactiveUI.SourceGenerators.Roslyn480.csproj" ReferenceOutputAssembly="false" />
</ItemGroup>
Expand All @@ -37,5 +38,6 @@
<ItemGroup>
<None Include="..\ReactiveUI.SourceGenerators.Roslyn480\bin\$(Configuration)\netstandard2.0\ReactiveUI.SourceGenerators.dll" PackagePath="analyzers\dotnet\roslyn4.8\cs" Pack="true" Visible="false" />
<None Include="..\ReactiveUI.SourceGenerators.Roslyn4120\\bin\$(Configuration)\netstandard2.0\ReactiveUI.SourceGenerators.dll" PackagePath="analyzers\dotnet\roslyn4.12\cs" Pack="true" Visible="false" />
<None Include="..\ReactiveUI.SourceGenerators.Roslyn5000\\bin\$(Configuration)\netstandard2.0\ReactiveUI.SourceGenerators.dll" PackagePath="analyzers\dotnet\roslyn5.0\cs" Pack="true" Visible="false" />
</ItemGroup>
</Project>
Loading