Skip to content

Commit 03ee299

Browse files
authored
Add Access Modifier To OAPH backing property (#159)
* Add Access Modifier To OAPH backing property * Update README.md
1 parent 3a78bfa commit 03ee299

File tree

25 files changed

+285
-31
lines changed

25 files changed

+285
-31
lines changed

README.md

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -185,18 +185,39 @@ using ReactiveUI.SourceGenerators;
185185

186186
public partial class MyReactiveClass : ReactiveObject
187187
{
188+
[ObservableAsProperty(ReadOnly = false)]
189+
private string _myProperty = "Default Value";
190+
188191
public MyReactiveClass()
189192
{
190-
// default value for TestValueProperty prior to initialization.
191-
_testValueProperty = "Test Value Pre Init";
193+
this.WhenActivated(disposables =>
194+
{
195+
_myPrpertyHelper = MyPropertyObservable()
196+
.ToProperty(this, x => x.MyProperty)
197+
.DisposeWith(disposables);
198+
});
199+
}
192200

193-
// Initialize generated _testValuePropertyHelper
194-
// for the generated TestValueProperty
195-
InitializeOAPH();
201+
IObservable<string> MyPropertyObservable() => Observable.Return("Test Value");
202+
}
203+
```
204+
205+
### Usage ObservableAsPropertyHelper with Observable Property and protected OAPH field
206+
```csharp
207+
using ReactiveUI.SourceGenerators;
208+
209+
public partial class MyReactiveClass : ReactiveObject
210+
{
211+
[ObservableAsProperty(UseProtected = true)]
212+
private string _myProperty = "Default Value";
213+
214+
public MyReactiveClass()
215+
{
216+
_myPrpertyHelper = MyPropertyObservable()
217+
.ToProperty(this, x => x.MyProperty);
196218
}
197219

198-
[ObservableAsProperty(PropertyName = TestValueProperty)]
199-
IObservable<string> MyObservable => Observable.Return("Test Value");
220+
IObservable<string> MyPropertyObservable() => Observable.Return("Test Value");
200221
}
201222
```
202223

@@ -238,6 +259,24 @@ public partial class MyReactiveClass : ReactiveObject
238259
}
239260
```
240261

262+
### Usage ObservableAsPropertyHelper with Observable Method and protected OAPH field
263+
```csharp
264+
using ReactiveUI.SourceGenerators;
265+
266+
public partial class MyReactiveClass : ReactiveObject
267+
{
268+
public MyReactiveClass()
269+
{
270+
// Initialize generated _myObservablePropertyHelper
271+
// for the generated MyObservableProperty
272+
InitializeOAPH();
273+
}
274+
275+
[ObservableAsProperty(UseProtected = true)]
276+
IObservable<string> MyObservable() => Observable.Return("Test Value");
277+
}
278+
```
279+
241280
## Usage ReactiveCommand `[ReactiveCommand]`
242281

243282
### Usage ReactiveCommand without parameter

src/ReactiveUI.SourceGenerator.Tests/OAPH/OAPFromObservableGeneratorTests.FromObservableMethods#ReactiveUI.SourceGenerators.ObservableAsPropertyAttribute.g.verified.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ internal sealed class ObservableAsPropertyAttribute : Attribute
3333
/// The is read only of the OAPH property.
3434
/// </value>
3535
public bool ReadOnly { get; init; } = true;
36+
37+
/// <summary>
38+
/// Gets the AccessModifier of the OAPH property.
39+
/// </summary>
40+
/// <value>
41+
/// The AccessModifier of the OAPH property, protected if true.
42+
/// </value>
43+
public bool UseProtected { get; init; } = false;
3644
}
3745
#nullable restore
3846
#pragma warning restore

src/ReactiveUI.SourceGenerator.Tests/OAPH/OAPFromObservableGeneratorTests.FromObservableMethodsWithName#ReactiveUI.SourceGenerators.ObservableAsPropertyAttribute.g.verified.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ internal sealed class ObservableAsPropertyAttribute : Attribute
3333
/// The is read only of the OAPH property.
3434
/// </value>
3535
public bool ReadOnly { get; init; } = true;
36+
37+
/// <summary>
38+
/// Gets the AccessModifier of the OAPH property.
39+
/// </summary>
40+
/// <value>
41+
/// The AccessModifier of the OAPH property, protected if true.
42+
/// </value>
43+
public bool UseProtected { get; init; } = false;
3644
}
3745
#nullable restore
3846
#pragma warning restore

src/ReactiveUI.SourceGenerator.Tests/OAPH/OAPFromObservableGeneratorTests.FromObservableProp#ReactiveUI.SourceGenerators.ObservableAsPropertyAttribute.g.verified.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ internal sealed class ObservableAsPropertyAttribute : Attribute
3333
/// The is read only of the OAPH property.
3434
/// </value>
3535
public bool ReadOnly { get; init; } = true;
36+
37+
/// <summary>
38+
/// Gets the AccessModifier of the OAPH property.
39+
/// </summary>
40+
/// <value>
41+
/// The AccessModifier of the OAPH property, protected if true.
42+
/// </value>
43+
public bool UseProtected { get; init; } = false;
3644
}
3745
#nullable restore
3846
#pragma warning restore

src/ReactiveUI.SourceGenerator.Tests/OAPH/OAPFromObservableGeneratorTests.FromObservablePropNestedClasses#ReactiveUI.SourceGenerators.ObservableAsPropertyAttribute.g.verified.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ internal sealed class ObservableAsPropertyAttribute : Attribute
3333
/// The is read only of the OAPH property.
3434
/// </value>
3535
public bool ReadOnly { get; init; } = true;
36+
37+
/// <summary>
38+
/// Gets the AccessModifier of the OAPH property.
39+
/// </summary>
40+
/// <value>
41+
/// The AccessModifier of the OAPH property, protected if true.
42+
/// </value>
43+
public bool UseProtected { get; init; } = false;
3644
}
3745
#nullable restore
3846
#pragma warning restore

src/ReactiveUI.SourceGenerator.Tests/OAPH/OAPFromObservableGeneratorTests.FromObservablePropertiesWithAttribute#ReactiveUI.SourceGenerators.ObservableAsPropertyAttribute.g.verified.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ internal sealed class ObservableAsPropertyAttribute : Attribute
3333
/// The is read only of the OAPH property.
3434
/// </value>
3535
public bool ReadOnly { get; init; } = true;
36+
37+
/// <summary>
38+
/// Gets the AccessModifier of the OAPH property.
39+
/// </summary>
40+
/// <value>
41+
/// The AccessModifier of the OAPH property, protected if true.
42+
/// </value>
43+
public bool UseProtected { get; init; } = false;
3644
}
3745
#nullable restore
3846
#pragma warning restore

src/ReactiveUI.SourceGenerator.Tests/OAPH/OAPFromObservableGeneratorTests.FromObservablePropertiesWithAttributeNullableRef#ReactiveUI.SourceGenerators.ObservableAsPropertyAttribute.g.verified.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ internal sealed class ObservableAsPropertyAttribute : Attribute
3333
/// The is read only of the OAPH property.
3434
/// </value>
3535
public bool ReadOnly { get; init; } = true;
36+
37+
/// <summary>
38+
/// Gets the AccessModifier of the OAPH property.
39+
/// </summary>
40+
/// <value>
41+
/// The AccessModifier of the OAPH property, protected if true.
42+
/// </value>
43+
public bool UseProtected { get; init; } = false;
3644
}
3745
#nullable restore
3846
#pragma warning restore

src/ReactiveUI.SourceGenerator.Tests/OAPH/OAPFromObservableGeneratorTests.FromObservablePropertiesWithAttributeRef#ReactiveUI.SourceGenerators.ObservableAsPropertyAttribute.g.verified.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ internal sealed class ObservableAsPropertyAttribute : Attribute
3333
/// The is read only of the OAPH property.
3434
/// </value>
3535
public bool ReadOnly { get; init; } = true;
36+
37+
/// <summary>
38+
/// Gets the AccessModifier of the OAPH property.
39+
/// </summary>
40+
/// <value>
41+
/// The AccessModifier of the OAPH property, protected if true.
42+
/// </value>
43+
public bool UseProtected { get; init; } = false;
3644
}
3745
#nullable restore
3846
#pragma warning restore

src/ReactiveUI.SourceGenerator.Tests/OAPH/OAPFromObservableGeneratorTests.FromObservablePropertiesWithName#ReactiveUI.SourceGenerators.ObservableAsPropertyAttribute.g.verified.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ internal sealed class ObservableAsPropertyAttribute : Attribute
3333
/// The is read only of the OAPH property.
3434
/// </value>
3535
public bool ReadOnly { get; init; } = true;
36+
37+
/// <summary>
38+
/// Gets the AccessModifier of the OAPH property.
39+
/// </summary>
40+
/// <value>
41+
/// The AccessModifier of the OAPH property, protected if true.
42+
/// </value>
43+
public bool UseProtected { get; init; } = false;
3644
}
3745
#nullable restore
3846
#pragma warning restore

src/ReactiveUI.SourceGenerator.Tests/OAPH/OAPGeneratorTests.FromField#ReactiveUI.SourceGenerators.ObservableAsPropertyAttribute.g.verified.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ internal sealed class ObservableAsPropertyAttribute : Attribute
3333
/// The is read only of the OAPH property.
3434
/// </value>
3535
public bool ReadOnly { get; init; } = true;
36+
37+
/// <summary>
38+
/// Gets the AccessModifier of the OAPH property.
39+
/// </summary>
40+
/// <value>
41+
/// The AccessModifier of the OAPH property, protected if true.
42+
/// </value>
43+
public bool UseProtected { get; init; } = false;
3644
}
3745
#nullable restore
3846
#pragma warning restore

0 commit comments

Comments
 (0)