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
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
//HintName: TestNs.TestVM.ObservableAsProperties.g.cs
//HintName: TestVM.ObservableAsProperties.g.cs
// <auto-generated/>
#pragma warning disable
#nullable enable
namespace TestNs
{
/// <inheritdoc/>
partial class TestVM
public partial class TestVM
{
/// <inheritdoc cref="_test1Helper"/>
[global::System.CodeDom.Compiler.GeneratedCode("ReactiveUI.SourceGenerators.ObservableAsPropertyGenerator", "1.1.0.0")]
/// <inheritdoc cref="_test1Helper"/>
private readonly ReactiveUI.ObservableAsPropertyHelper<int> _test1Helper;

/// <inheritdoc cref="_test1"/>
[global::System.CodeDom.Compiler.GeneratedCode("ReactiveUI.SourceGenerators.ObservableAsPropertyGenerator", "1.1.0.0")]
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
public int Test1 { get => _test1 = _test1Helper?.Value ?? _test1; }
}
}
}
#nullable restore
#pragma warning restore
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
//HintName: TestNs.TestVM.ObservableAsProperties.g.cs
//HintName: TestVM.ObservableAsProperties.g.cs
// <auto-generated/>
#pragma warning disable
#nullable enable
namespace TestNs
{
/// <inheritdoc/>
partial class TestVM
public partial class TestVM
{
/// <inheritdoc cref="_test2Helper"/>
[global::System.CodeDom.Compiler.GeneratedCode("ReactiveUI.SourceGenerators.ObservableAsPropertyGenerator", "1.1.0.0")]
/// <inheritdoc cref="_test2Helper"/>
private readonly ReactiveUI.ObservableAsPropertyHelper<int> _test2Helper;

/// <inheritdoc cref="_test2"/>
[global::System.CodeDom.Compiler.GeneratedCode("ReactiveUI.SourceGenerators.ObservableAsPropertyGenerator", "1.1.0.0")]
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
public int Test2 { get => _test2 = _test2Helper?.Value ?? _test2; }
}
}
}
#nullable restore
#pragma warning restore
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
//HintName: TestNs.TestVM.ObservableAsProperties.g.cs
//HintName: TestVM.ObservableAsProperties.g.cs
// <auto-generated/>
#pragma warning disable
#nullable enable
namespace TestNs
{
/// <inheritdoc/>
partial class TestVM
public partial class TestVM
{
/// <inheritdoc cref="_test2Helper"/>
[global::System.CodeDom.Compiler.GeneratedCode("ReactiveUI.SourceGenerators.ObservableAsPropertyGenerator", "1.1.0.0")]
/// <inheritdoc cref="_test2Helper"/>
private readonly ReactiveUI.ObservableAsPropertyHelper<int> _test2Helper;

/// <inheritdoc cref="_test2"/>
[global::System.CodeDom.Compiler.GeneratedCode("ReactiveUI.SourceGenerators.ObservableAsPropertyGenerator", "1.1.0.0")]
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
public int Test2 { get => _test2 = _test2Helper?.Value ?? _test2; }
}
}
}
#nullable restore
#pragma warning restore
7 changes: 7 additions & 0 deletions src/ReactiveUI.SourceGenerators.Execute/TestViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ public partial class TestViewModel : ReactiveObject, IActivatableViewModel, IDis
[ObservableAsProperty(ReadOnly = false)]
private double? _test11Property = 11.1d;

[ObservableAsProperty(ReadOnly = false)]
private double _test13Property = 11.1d;

[property: Test(AParameter = "Test Input")]
[Reactive]
private double? _test12Property = 12.1d;
Expand Down Expand Up @@ -138,6 +141,10 @@ public TestViewModel()
Console.Out.WriteLine(_myReadOnlyNonNullProperty);
_testNonNullSubject.OnNext(default);

Console.Out.WriteLine(_test13Property);
Console.Out.WriteLine(Test13Property);
Console.Out.WriteLine(_test13PropertyHelper);

// expected value 0 as the _testNonNullSubject has been updated.
Console.Out.WriteLine(MyReadOnlyNonNullProperty);
Console.Out.WriteLine(_myReadOnlyNonNullProperty);
Expand Down
3 changes: 2 additions & 1 deletion src/ReactiveUI.SourceGenerators/AttributeDefinitions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ namespace ReactiveUI.SourceGenerators.Helpers;
internal static class AttributeDefinitions
{
public const string GeneratedCode = "global::System.CodeDom.Compiler.GeneratedCode";
public const string ExcludeFromCodeCoverage = "global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage";
public const string Obsolete = "global::System.Obsolete";

public const string AccessModifierType = "ReactiveUI.SourceGenerators.AccessModifier";
public static string[] ExcludeFromCodeCoverage = ["[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]"];
public static string ExcludeFromCodeCoverageString = "global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage";

public static string GetAccessModifierEnum() => $$"""
// Copyright (c) {{DateTime.Now.Year}} .NET Foundation and Contributors. All rights reserved.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ namespace {{containingNamespace}}
/// Partial class for the {{containingTypeName}} which contains ReactiveUI IViewFor initialization.
/// </summary>
{{forwardedAttributesString}}
partial class {{containingTypeName}} : IViewFor<{{iviewForInfo.ViewModelTypeName}}>
{{containingClassVisibility}} partial {{containingType}} {{containingTypeName}} : IViewFor<{{iviewForInfo.ViewModelTypeName}}>
{
/// <inheritdoc/>
[Category("ReactiveUI")]
Expand Down Expand Up @@ -223,7 +223,7 @@ namespace {{containingNamespace}}
/// Partial class for the {{containingTypeName}} which contains ReactiveUI IViewFor initialization.
/// </summary>
{{forwardedAttributesString}}
public partial class {{containingTypeName}} : IViewFor<{{iviewForInfo.ViewModelTypeName}}>
{{containingClassVisibility}} partial {{containingType}} {{containingTypeName}} : IViewFor<{{iviewForInfo.ViewModelTypeName}}>
{
/// <summary>
/// The view model dependency property.
Expand Down Expand Up @@ -282,7 +282,7 @@ namespace {{containingNamespace}}
/// Partial class for the {{containingTypeName}} which contains ReactiveUI IViewFor initialization.
/// </summary>
{{forwardedAttributesString}}
public partial class {{containingTypeName}} : IViewFor<{{iviewForInfo.ViewModelTypeName}}>
{{containingClassVisibility}} partial {{containingType}} {{containingTypeName}} : IViewFor<{{iviewForInfo.ViewModelTypeName}}>
{
public static readonly BindableProperty ViewModelProperty = BindableProperty.Create(nameof(ViewModel), typeof({{iviewForInfo.ViewModelTypeName}}), typeof(IViewFor<{{iviewForInfo.ViewModelTypeName}}>), default({{iviewForInfo.ViewModelTypeName}}), BindingMode.OneWay, propertyChanged: OnViewModelChanged);

Expand Down
Loading