Skip to content

Commit

Permalink
Update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisPulman committed Aug 31, 2024
1 parent 0be0cfd commit 190f169
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 8 deletions.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -365,5 +365,26 @@ public partial class MyReactiveControl : UserControl
}
```

## Platform specific Attributes

### WinForms

#### RoutedControlHost
```csharp
using ReactiveUI.SourceGenerators.WinForms;

[RoutedControlHost("YourNameSpace.CustomControl")]
public partial class MyCustomRoutedControlHost;
```

#### ViewModelControlHost
```csharp
using ReactiveUI.SourceGenerators.WinForms;

[ViewModelControlHost("YourNameSpace.CustomControl")]
public partial class MyCustomViewModelControlHost;
```


### TODO:
- Add ObservableAsProperty to generate from a IObservable method with parameters.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using ReactiveUI.SourceGenerators.Helpers;
using ReactiveUI.SourceGenerators.Input.Models;
using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;

Expand Down Expand Up @@ -66,7 +67,7 @@ internal static CompilationUnitSyntax GetIViewForWpfWinUiUno(IViewForInfo iViewF
IdentifierName(iViewForInfo.ViewModelTypeName))))))
.AddModifiers([.. iViewForInfo.DeclarationSyntax.Modifiers])
.AddAttributeLists(AttributeList(SingletonSeparatedList(
Attribute(IdentifierName(GeneratedCode))
Attribute(IdentifierName(AttributeDefinitions.GeneratedCode))
.AddArgumentListArguments(
AttributeArgument(LiteralExpression(SyntaxKind.StringLiteralExpression, Literal(typeof(IViewForGenerator).FullName))),
AttributeArgument(LiteralExpression(SyntaxKind.StringLiteralExpression, Literal(typeof(IViewForGenerator).Assembly.GetName().Version.ToString())))))))))
Expand Down Expand Up @@ -159,7 +160,7 @@ internal static CompilationUnitSyntax GetIViewForWinForms(IViewForInfo iViewForI
IdentifierName(iViewForInfo.ViewModelTypeName))))))
.AddModifiers([.. iViewForInfo.DeclarationSyntax.Modifiers])
.AddAttributeLists(AttributeList(SingletonSeparatedList(
Attribute(IdentifierName(GeneratedCode))
Attribute(IdentifierName(AttributeDefinitions.GeneratedCode))
.AddArgumentListArguments(
AttributeArgument(LiteralExpression(SyntaxKind.StringLiteralExpression, Literal(typeof(IViewForGenerator).FullName))),
AttributeArgument(LiteralExpression(SyntaxKind.StringLiteralExpression, Literal(typeof(IViewForGenerator).Assembly.GetName().Version.ToString())))))))))
Expand Down Expand Up @@ -232,7 +233,7 @@ internal static CompilationUnitSyntax GetIViewForAvalonia(IViewForInfo iViewForI
IdentifierName(iViewForInfo.ViewModelTypeName))))))
.AddModifiers([.. iViewForInfo.DeclarationSyntax.Modifiers])
.AddAttributeLists(AttributeList(SingletonSeparatedList(
Attribute(IdentifierName(GeneratedCode))
Attribute(IdentifierName(AttributeDefinitions.GeneratedCode))
.AddArgumentListArguments(
AttributeArgument(LiteralExpression(SyntaxKind.StringLiteralExpression, Literal(typeof(IViewForGenerator).FullName))),
AttributeArgument(LiteralExpression(SyntaxKind.StringLiteralExpression, Literal(typeof(IViewForGenerator).Assembly.GetName().Version.ToString())))))))))
Expand Down Expand Up @@ -346,7 +347,7 @@ internal static CompilationUnitSyntax GetIViewForMaui(IViewForInfo iViewForInfo)
IdentifierName(iViewForInfo.ViewModelTypeName))))))
.AddModifiers([.. iViewForInfo.DeclarationSyntax.Modifiers])
.AddAttributeLists(AttributeList(SingletonSeparatedList(
Attribute(IdentifierName(GeneratedCode))
Attribute(IdentifierName(AttributeDefinitions.GeneratedCode))
.AddArgumentListArguments(
AttributeArgument(LiteralExpression(SyntaxKind.StringLiteralExpression, Literal(typeof(IViewForGenerator).FullName))),
AttributeArgument(LiteralExpression(SyntaxKind.StringLiteralExpression, Literal(typeof(IViewForGenerator).Assembly.GetName().Version.ToString())))))))))
Expand Down
2 changes: 0 additions & 2 deletions src/ReactiveUI.SourceGenerators/IViewFor/IViewForGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ namespace ReactiveUI.SourceGenerators;
[Generator(LanguageNames.CSharp)]
public sealed partial class IViewForGenerator : IIncrementalGenerator
{
private const string GeneratedCode = "global::System.CodeDom.Compiler.GeneratedCode";

/// <inheritdoc/>
public void Initialize(IncrementalGeneratorInitializationContext context)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using ReactiveUI.SourceGenerators.Helpers;
using ReactiveUI.SourceGenerators.Input.Models;
using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;

Expand Down Expand Up @@ -82,7 +83,12 @@ internal static CompilationUnitSyntax GetRoutedControlHost(RoutedControlHostInfo
SimpleBaseType(IdentifierName(vmcInfo.ViewModelTypeName)),
Token(SyntaxKind.CommaToken),
SimpleBaseType(IdentifierName("IReactiveObject"))
})))))))
})))
.AddAttributeLists(AttributeList(SingletonSeparatedList(
Attribute(IdentifierName(AttributeDefinitions.GeneratedCode))
.AddArgumentListArguments(
AttributeArgument(LiteralExpression(SyntaxKind.StringLiteralExpression, Literal(typeof(RoutedControlHostGenerator).FullName))),
AttributeArgument(LiteralExpression(SyntaxKind.StringLiteralExpression, Literal(typeof(RoutedControlHostGenerator).Assembly.GetName().Version.ToString())))))))))))
.NormalizeWhitespace().ToFullString();

// Remove the last 4 characters to remove the closing brackets
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using ReactiveUI.SourceGenerators.Helpers;
using ReactiveUI.SourceGenerators.Input.Models;
using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;

Expand Down Expand Up @@ -84,7 +85,12 @@ internal static CompilationUnitSyntax GetViewModelControlHost(ViewModelControlHo
SimpleBaseType(IdentifierName("IReactiveObject")),
Token(SyntaxKind.CommaToken),
SimpleBaseType(IdentifierName("IViewFor"))
})))))))
})))
.AddAttributeLists(AttributeList(SingletonSeparatedList(
Attribute(IdentifierName(AttributeDefinitions.GeneratedCode))
.AddArgumentListArguments(
AttributeArgument(LiteralExpression(SyntaxKind.StringLiteralExpression, Literal(typeof(ViewModelControlHostGenerator).FullName))),
AttributeArgument(LiteralExpression(SyntaxKind.StringLiteralExpression, Literal(typeof(ViewModelControlHostGenerator).Assembly.GetName().Version.ToString())))))))))))
.NormalizeWhitespace().ToFullString();

// Remove the last 4 characters to remove the closing brackets
Expand Down

0 comments on commit 190f169

Please sign in to comment.