Skip to content

Added static properties and supports nullable fields #36

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Jul 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
895f368
Removed readonly option from both attributes since we can read from t…
ShawnLaMountain Jul 11, 2025
288222e
Merge branch 'main' of https://github.com/ShawnLaMountain/ThunderDesi…
ShawnLaMountain Jul 11, 2025
403bd50
Update CD.yml for Testing
ShawnLaMountain Jul 11, 2025
74495d5
For readonly properties, use getter accessibility as property accessi…
ShawnLaMountain Jul 11, 2025
98592bf
Merge branch 'main' of https://github.com/ShawnLaMountain/ThunderDesi…
ShawnLaMountain Jul 11, 2025
ae12e25
Update CD.yml for Testing
ShawnLaMountain Jul 11, 2025
101336e
Added the ability to use static properties with the Property attribute
ShawnLaMountain Jul 11, 2025
030a474
Merge branch 'main' of https://github.com/ShawnLaMountain/ThunderDesi…
ShawnLaMountain Jul 11, 2025
6632c25
Update CD.yml for Testing
ShawnLaMountain Jul 11, 2025
0febec9
Now only added _Locker for non static fields
ShawnLaMountain Jul 11, 2025
d15d4da
Merge branch 'main' of https://github.com/ShawnLaMountain/ThunderDesi…
ShawnLaMountain Jul 11, 2025
cbddf86
Update CD.yml for Testing
ShawnLaMountain Jul 11, 2025
3fc7d1b
Only generate SetStaticProperty if we have writable static fields
ShawnLaMountain Jul 11, 2025
88cdf40
Merge branch 'main' of https://github.com/ShawnLaMountain/ThunderDesi…
ShawnLaMountain Jul 11, 2025
1b6cfec
Update CD.yml for Testing
ShawnLaMountain Jul 11, 2025
93488c0
Updated ReadMe file to include static properties
ShawnLaMountain Jul 11, 2025
0a41933
Merge branch 'main' of https://github.com/ShawnLaMountain/ThunderDesi…
ShawnLaMountain Jul 11, 2025
24b03c1
Update CD.yml for production
ShawnLaMountain Jul 11, 2025
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
6 changes: 3 additions & 3 deletions .github/workflows/CD.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ jobs:
shell: pwsh

- name: Create NuGet Package
# run: nuget pack ThunderDesign.Net-PCL.nuspec -Version 2.0.17 -OutputDirectory ${{ env.PACKAGE_OUTPUT_DIRECTORY }}
# run: nuget pack ThunderDesign.Net-PCL.nuspec -Version 2.1.0.5 -OutputDirectory ${{ env.PACKAGE_OUTPUT_DIRECTORY }}
run: nuget pack ThunderDesign.Net-PCL.nuspec -Version ${{ github.event.release.tag_name }} -OutputDirectory ${{ env.PACKAGE_OUTPUT_DIRECTORY }}

- name: Archive NuGet Package
uses: actions/upload-artifact@v4
with:
# name: Package_${{ env.FILE_NAME}}.2.0.17
# path: ${{ env.PACKAGE_OUTPUT_DIRECTORY}}\${{ env.FILE_NAME}}.2.0.17.nupkg
# name: Package_${{ env.FILE_NAME}}.2.1.0.5
# path: ${{ env.PACKAGE_OUTPUT_DIRECTORY}}\${{ env.FILE_NAME}}.2.1.0.5.nupkg
name: Package_${{ env.FILE_NAME}}.${{ github.event.release.tag_name }}
path: ${{ env.PACKAGE_OUTPUT_DIRECTORY}}\${{ env.FILE_NAME}}.${{ github.event.release.tag_name }}.nupkg

Expand Down
46 changes: 46 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,52 @@ public partial class Person : IBindableObject, INotifyPropertyChanged

---

### Advanced: Static Properties

The `[Property]` attribute now supports static fields, allowing you to generate thread-safe static properties with automatic locking mechanisms.

#### Example
```csharp
using ThunderDesign.Net.Threading.Attributes;

public partial class AppSettings
{
[Property]
private static string _applicationName = "MyApp";

[Property(getter: AccessorAccessibility.Internal)]
private static readonly string _version = "1.0.0";
}
```

**What gets generated:**

```csharp
public partial class AppSettings
{
static readonly object _StaticLocker = new object();

public static string ApplicationName
{
get { return GetStaticProperty(ref _applicationName, _StaticLocker); }
set { SetStaticProperty(ref _applicationName, value, _StaticLocker); }
}

internal static string Version
{
get { return GetStaticProperty(ref _version, _StaticLocker); }
}

// Helper methods for static property access
public static T GetStaticProperty<T>(ref T backingStore, object? lockObj = null) { /* ... */ }
public static bool SetStaticProperty<T>(ref T backingStore, T value, object? lockObj = null) { /* ... */ }
}
```

> **Note:** Static properties are only supported with the `[Property]` attribute. Use the `readonly` field modifier to create read-only static properties.

---

## Installation

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