Skip to content

Commit 93488c0

Browse files
Updated ReadMe file to include static properties
1 parent 88cdf40 commit 93488c0

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,52 @@ public partial class Person : IBindableObject, INotifyPropertyChanged
275275
276276
---
277277

278+
### Advanced: Static Properties
279+
280+
The `[Property]` attribute now supports static fields, allowing you to generate thread-safe static properties with automatic locking mechanisms.
281+
282+
#### Example
283+
```csharp
284+
using ThunderDesign.Net.Threading.Attributes;
285+
286+
public partial class AppSettings
287+
{
288+
[Property]
289+
private static string _applicationName = "MyApp";
290+
291+
[Property(getter: AccessorAccessibility.Internal)]
292+
private static readonly string _version = "1.0.0";
293+
}
294+
```
295+
296+
**What gets generated:**
297+
298+
```csharp
299+
public partial class AppSettings
300+
{
301+
static readonly object _StaticLocker = new object();
302+
303+
public static string ApplicationName
304+
{
305+
get { return GetStaticProperty(ref _applicationName, _StaticLocker); }
306+
set { SetStaticProperty(ref _applicationName, value, _StaticLocker); }
307+
}
308+
309+
internal static string Version
310+
{
311+
get { return GetStaticProperty(ref _version, _StaticLocker); }
312+
}
313+
314+
// Helper methods for static property access
315+
public static T GetStaticProperty<T>(ref T backingStore, object? lockObj = null) { /* ... */ }
316+
public static bool SetStaticProperty<T>(ref T backingStore, T value, object? lockObj = null) { /* ... */ }
317+
}
318+
```
319+
320+
> **Note:** Static properties are only supported with the `[Property]` attribute. Use the `readonly` field modifier to create read-only static properties.
321+
322+
---
323+
278324
## Installation
279325

280326
Grab the latest [ThunderDesign.Net-PCL.Threading NuGet](https://www.nuget.org/packages/ThunderDesign.Net-PCL.Threading) package and install in your solution.

0 commit comments

Comments
 (0)