Skip to content

Commit

Permalink
chore: Update readme/project references (#113)
Browse files Browse the repository at this point in the history
  • Loading branch information
glennawatson authored Nov 6, 2024
1 parent 93f0934 commit 4574c70
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 29 deletions.
68 changes: 48 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,55 @@
# ReactiveUI.SourceGenerators
Use source generators to generate ReactiveUI objects.
The minimum C# version is 12.0 and the minimum Visual Studio version is 17.8.0.
# ReactiveUI Source Generators Documentation

These Source Generators were designed to work in full with ReactiveUI V19.5.31 and newer supporting all features, currently:
- [Reactive]
- [ObservableAsProperty]
- [ObservableAsProperty(PropertyName = "ReadOnlyPropertyName")]
- [ReactiveCommand]
- [ReactiveCommand(CanExecute = nameof(IObservableBoolName))] with CanExecute
- [ReactiveCommand][property: AttribueToAddToCommand] with Attribute passthrough
- [IViewFor(nameof(ViewModelName))]
- [RoutedControlHost("YourNameSpace.CustomControl")]
- [ViewModelControlHost("YourNameSpace.CustomControl")]
This documentation covers using ReactiveUI Source Generators to simplify and enhance the use of ReactiveUI objects.

Versions older than V19.5.31 to this:
- [ReactiveCommand] all options supported except Cancellation Token asnyc methods.
- **Minimum Requirements**:
- **C# Version**: 12.0
- **Visual Studio Version**: 17.8.0
- **ReactiveUI Version**: 19.5.31+

For dot net framework 4.8 and older versions please add Polyfill or PolySharp package to your project to gain the IsExternalInit class and set the LangVersion to 12.0 or latest in your project file.
## Overview

[analyzer codes](https://github.com/reactiveui/ReactiveUI.SourceGenerators/blob/main/src/ReactiveUI.SourceGenerators/AnalyzerReleases.Shipped.md)
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:

# Historical ways
## Read-write properties
Typically properties are declared like this:
- `[Reactive]`
- `[ObservableAsProperty]`
- `[ObservableAsProperty(PropertyName = "ReadOnlyPropertyName")]`
- `[ReactiveCommand]`
- `[ReactiveCommand(CanExecute = nameof(IObservableBoolName))]` with CanExecute
- `[ReactiveCommand][property: AttributeToAddToCommand]` with Attribute passthrough
- `[IViewFor(nameof(ViewModelName))]`
- `[RoutedControlHost("YourNameSpace.CustomControl")]`
- `[ViewModelControlHost("YourNameSpace.CustomControl")]`

### Compatibility Notes
- For ReactiveUI versions **older than V19.5.31**, all `[ReactiveCommand]` options are supported except for async methods with a `CancellationToken`.
- For **.NET Framework 4.8 and older**, add [Polyfill by Simon Cropp](https://github.com/Fody/Polyfill) or [PolySharp by Manuel Römer](https://github.com/manuelroemer/PolySharp) to your project and set the `LangVersion` to 12.0 or later in your project file.

For more information on analyzer codes, see the [analyzer codes documentation](https://github.com/reactiveui/ReactiveUI.SourceGenerators/blob/main/src/ReactiveUI.SourceGenerators/AnalyzerReleases.Shipped.md).

---

## Supported Attributes

### `[Reactive]`
Marks properties as reactive, generating getter and setter code.

### `[ObservableAsProperty]`
Generates read-only properties backed by an `ObservableAsPropertyHelper` based on an `IObservable`.

### `[ReactiveCommand]`
Generates commands, with options to add attributes or enable `CanExecute` functionality.

### `[IViewFor]`
Links a view to a view model for data binding.

### `[RoutedControlHost]` and `[ViewModelControlHost]`
Platform-specific attributes for control hosting in WinForms applications.

## Historical Approach

### Read-Write Properties
Previously, properties were declared like this:

```csharp
private string _name;
Expand All @@ -35,6 +62,7 @@ public string Name

Before these Source Generators were avaliable we used ReactiveUI.Fody.
With ReactiveUI.Fody the `[Reactive]` Attribute was placed on a Public Property with Auto get / set properties, the generated code from the Source Generator and the Injected code using Fody are very similar with the exception of the Attributes.

```csharp
[Reactive]
public string Name { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

<ItemGroup>
<ProjectReference Include="..\ReactiveUI.SourceGenerators\ReactiveUI.SourceGenerators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
<ProjectReference Include="..\ReactiveUI.SourceGenerators.CodeFixers\ReactiveUI.CodeFixes.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
<ProjectReference Include="..\ReactiveUI.SourceGenerators.Analyzers.CodeFixes\ReactiveUI.SourceGenerators.Analyzers.CodeFixes.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\ReactiveUI.SourceGenerators.Analyzers.CodeFixes\ReactiveUI.SourceGenerators.Analyzers.CodeFixes.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
<ProjectReference Include="..\ReactiveUI.SourceGenerators\ReactiveUI.SourceGenerators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
<ProjectReference Include="..\ReactiveUI.SourceGenerators.CodeFixers\ReactiveUI.CodeFixes.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
</ItemGroup>
</Project>
12 changes: 6 additions & 6 deletions src/ReactiveUI.SourceGenerators.sln
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# 17
# Visual Studio Version 17
VisualStudioVersion = 17.10.35027.167
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SolutionConfig", "SolutionConfig", "{F29AF2F3-DEC8-58BC-043A-1447862C832D}"
Expand All @@ -24,7 +24,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ReactiveUI.SourceGenerators
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "TestLibs", "TestLibs", "{B86ED9C1-AFFB-4854-AD80-F4B4050CAD0A}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ReactiveUI.SourceGenerators.Analyzers.CodeFixes", "ReactiveUI.SourceGenerators.CodeFixers\ReactiveUI.SourceGenerators.Analyzers.CodeFixes.csproj", "{C89EE66E-E1DC-4A31-9322-20D95CB0D74D}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ReactiveUI.SourceGenerators.Analyzers.CodeFixes", "ReactiveUI.SourceGenerators.Analyzers.CodeFixes\ReactiveUI.SourceGenerators.Analyzers.CodeFixes.csproj", "{BD4FADD9-C0E5-46E9-906E-01B04CC856B5}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -48,10 +48,10 @@ Global
{60C7C031-8765-46D7-8E0D-88CD4949F25B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{60C7C031-8765-46D7-8E0D-88CD4949F25B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{60C7C031-8765-46D7-8E0D-88CD4949F25B}.Release|Any CPU.Build.0 = Release|Any CPU
{C89EE66E-E1DC-4A31-9322-20D95CB0D74D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C89EE66E-E1DC-4A31-9322-20D95CB0D74D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C89EE66E-E1DC-4A31-9322-20D95CB0D74D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C89EE66E-E1DC-4A31-9322-20D95CB0D74D}.Release|Any CPU.Build.0 = Release|Any CPU
{BD4FADD9-C0E5-46E9-906E-01B04CC856B5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BD4FADD9-C0E5-46E9-906E-01B04CC856B5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BD4FADD9-C0E5-46E9-906E-01B04CC856B5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BD4FADD9-C0E5-46E9-906E-01B04CC856B5}.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 @@ -44,8 +44,9 @@
<ItemGroup>
<InternalsVisibleTo Include="ReactiveUI.CodeFixes" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\ReactiveUI.SourceGenerators.CodeFixers\ReactiveUI.SourceGenerators.Analyzers.CodeFixes.csproj" />
<ProjectReference Include="..\ReactiveUI.SourceGenerators.Analyzers.CodeFixes\ReactiveUI.SourceGenerators.Analyzers.CodeFixes.csproj" />
</ItemGroup>

<!-- This ensures the library will be packaged as a source generator when we use `dotnet pack` -->
Expand Down

0 comments on commit 4574c70

Please sign in to comment.