Skip to content

Commit e4e05e6

Browse files
Updated ReadMe file
1 parent 67853c0 commit e4e05e6

File tree

1 file changed

+136
-7
lines changed

1 file changed

+136
-7
lines changed

README.md

Lines changed: 136 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,48 @@
1-
# ThunderDesign.Net-PCL.Threading
1+
# ThunderDesign.Net-PCL.Threading
22
[![CI](https://github.com/ThunderDesign/ThunderDesign.Net-PCL.Threading/actions/workflows/CI.yml/badge.svg)](https://github.com/ThunderDesign/ThunderDesign.Net-PCL.Threading/actions/workflows/CI.yml)
33
[![CD](https://github.com/ThunderDesign/ThunderDesign.Net-PCL.Threading/actions/workflows/CD.yml/badge.svg)](https://github.com/ThunderDesign/ThunderDesign.Net-PCL.Threading/actions/workflows/CD.yml)
44
[![Nuget](https://img.shields.io/nuget/v/ThunderDesign.Net-PCL.Threading)](https://www.nuget.org/packages/ThunderDesign.Net-PCL.Threading)
55
[![License](https://img.shields.io/github/license/ThunderDesign/ThunderDesign.Net-PCL.Threading)](https://github.com/ThunderDesign/ThunderDesign.Net-PCL.Threading/blob/main/LICENSE)
6-
[![Net](https://img.shields.io/badge/.net%20standard-v1.0%20--%20v2.1-blue)](https://github.com/ThunderDesign/ThunderDesign.Net-PCL.Threading/blob/main/README.md)
6+
[![NetStandard](https://img.shields.io/badge/.net%20standard-v1.0%20--%20v2.1-blue)](https://github.com/ThunderDesign/ThunderDesign.Net-PCL.Threading/blob/main/README.md)
7+
[![Net](https://img.shields.io/badge/.net%20-v6.0%20--%20v8.0-blue)](https://github.com/ThunderDesign/ThunderDesign.Net-PCL.Threading/blob/main/README.md)
8+
9+
---
710

811
A combination of generic Thread-Safe objects for .Net development.
912

13+
---
14+
15+
<div align="center">
16+
17+
<h2>🚀 <b>Now with .NET 8 support and built-in Source Generators!</b> 🚀</h2>
18+
19+
</div>
20+
21+
> - **.NET 8**: Take advantage of the latest .NET features and performance improvements.
22+
> - **Source Generators**: Eliminate boilerplate and let the library generate thread-safe, bindable properties for you automatically!
23+
>
24+
> _Get started faster, write less code, and enjoy modern .NET development!_
25+
1026
----
1127

1228
A simple C# repository containing a few basic useful Thread-Safe Objects.
1329
### Highlights include:
1430

1531
- Collections
16-
- ObservableDictionaryThreadSafe
17-
- ObservableCollectionThreadSafe
1832
- CollectionThreadSafe
1933
- DictionaryThreadSafe
20-
- SortedListThreadSafe
34+
- HashSetThreadSafe
35+
- LinkedListThreadSafe
2136
- ListThreadSafe
37+
- ObservableCollectionThreadSafe
38+
- ObservableDictionaryThreadSafe
2239
- QueueThreadSafe
40+
- SortedDictionaryThreadSafe
41+
- SortedListThreadSafe
42+
- StackThreadSafe
2343
- DataCollections
24-
- ObservableDataDictionary
2544
- ObservableDataCollection
45+
- ObservableDataDictionary
2646
- DataObjects
2747
- BindableDataObject
2848
- DataObject
@@ -33,10 +53,118 @@ A simple C# repository containing a few basic useful Thread-Safe Objects.
3353
- ObjectExtention
3454
- HelperClasses
3555
- ThreadHelper
56+
- Interfaces
57+
- IBindableCollection
58+
- IBindableDataObject
59+
- IBindableDataObject\<Key>
60+
- IBindableObject
61+
- ICollectionThreadSafe
62+
- IDataObject
63+
- IDataObject\<Key>
64+
- IDictionaryThreadSafe
65+
- IHashSetThreadSafe
66+
- ILinkedListThreadSafe
67+
- IListThreadSafe
68+
- IObservableDataCollection
69+
- IObservableDataCollection\<T>
70+
- ISortedDictionaryThreadSafe
71+
- IStackThreadSafe
3672
- Objects
3773
- BindableObject
3874
- ThreadObject
3975

76+
----
77+
78+
## Source Generators
79+
80+
The `ThunderDesign.Net-PCL.SourceGenerators` project provides Roslyn-based source generators that automate the creation of common boilerplate code for thread-safe and bindable objects in this library. By including this package in your project, you can reduce repetitive code and ensure consistency across your data and collection classes.
81+
82+
### What does it do?
83+
84+
- **Automatic Property Generation:**
85+
The source generator scans your code for fields marked with specific attributes (such as `[BindableProperty]` or `[Property]`) and automatically generates the corresponding properties, including thread-safe accessors and `INotifyPropertyChanged` support where appropriate.
86+
- **Interface Implementation:**
87+
If your class does not already implement interfaces like `IBindableObject`, the generator will add the necessary interface implementations and event wiring.
88+
- **Thread Safety:**
89+
Generated properties use locking patterns to ensure thread safety, matching the patterns used throughout the ThunderDesign.Net-PCL.Threading library.
90+
91+
### How to use
92+
93+
1. **Add the NuGet package:**
94+
Reference the `ThunderDesign.Net-PCL.SourceGenerators` package in your project. If you are building from source, add a project reference to `ThunderDesign.Net-PCL.SourceGenerators.csproj`.
95+
96+
2. **Annotate your fields:**
97+
Use `[BindableProperty]` or `[Property]` attributes on your fields to indicate which properties should be generated. The generator will handle the rest.
98+
99+
3. **Build your project:**
100+
When you build, the source generator will automatically add the generated code to your compilation. You do not need to manually include or maintain the generated files.
101+
102+
4. **Enjoy less boilerplate:**
103+
Your classes will have all the necessary properties, events, and thread-safety mechanisms without manual implementation.
104+
105+
> **Note:** Source generators require Visual Studio 2019 16.9+ or .NET SDK 5.0+ for full support.
106+
107+
### Example Usage
108+
109+
Suppose you want to create a thread-safe, bindable object with automatic property and notification support.
110+
With the source generator, you only need to annotate your fields:
111+
112+
```csharp
113+
using ThunderDesign.Net.Threading.Attributes;
114+
public partial class Person
115+
{
116+
[BindableProperty]
117+
private string _name;
118+
119+
[Property]
120+
private int _age;
121+
}
122+
```
123+
124+
**What gets generated:**
125+
- A public `Name` property with thread-safe getter/setter and `INotifyPropertyChanged` support.
126+
- A public `Age` property with thread-safe getter/setter.
127+
128+
```csharp
129+
using System.ComponentModel;
130+
using System.Runtime.CompilerServices;
131+
using ThunderDesign.Net.Threading.Extentions;
132+
using ThunderDesign.Net.Threading.Interfaces;
133+
134+
public partial class Person : IBindableObject, INotifyPropertyChanged
135+
{
136+
public event PropertyChangedEventHandler PropertyChanged;
137+
138+
protected readonly object _Locker = new object();
139+
140+
public string Name
141+
{
142+
get { return this.GetProperty(ref _name, _Locker); }
143+
set { this.SetProperty(ref _name, value, _Locker, true); }
144+
}
145+
146+
public int Age
147+
{
148+
get { return this.GetProperty(ref _age, _Locker); }
149+
set { this.SetProperty(ref _age, value, _Locker); }
150+
}
151+
}
152+
```
153+
154+
You can now use your `Person` class like this:
155+
156+
```csharp
157+
var person = new Person();
158+
person.Name = "Alice";
159+
person.Age = 30; // PropertyChanged event will be raised for Name changes if you subscribe to it.
160+
```
161+
162+
163+
**No need to manually implement** property notification, thread safety, or boilerplate code—the generator does it for you!
164+
165+
> For more advanced scenarios, you can use attribute parameters to control property behavior (e.g., read-only, also notify other properties, etc.).
166+
167+
40168
----
41169

42170
## Installation
@@ -74,4 +202,5 @@ This can be overwritten durring creation or by setting Property `WaitOnNotifyCol
74202

75203
Observable Objects Property `WaitOnNotifyPropertyChanged` has been renamed to Property `WaitOnNotifying`.
76204

77-
Observable Collections Property `WaitOnNotifyCollectionChanged` has been removed and now uses Property `WaitOnNotifying`.
205+
Observable Collections Property `WaitOnNotifyCollectionChanged` has been removed and now uses Property `WaitOnNotifying`.
206+
----

0 commit comments

Comments
 (0)