Skip to content

Commit fe8aa2d

Browse files
authored
housekeeping: add instructions how to use.
1 parent baf4adf commit fe8aa2d

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

README.md

+65
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,68 @@
22

33
This project is a .NET 5 source generator which produces `IObservable<T>` for events contained within a object including all base classes.
44

5+
# Installation
6+
7+
## NuGet Packages
8+
9+
Install the following packages to start using Observable Events.
10+
11+
| Name | Platform | NuGet |
12+
| ----------------------------- | ----------------- | -------------------------------- |
13+
| [ReactiveMarbles.ObservableEvents.SourceGenerator][Core] | Core - Libary | [![CoreBadge]][Core] |
14+
15+
16+
[Core]: https://www.nuget.org/packages/ReactiveMarbles.ObservableEvents.SourceGenerator/
17+
[CoreBadge]: https://img.shields.io/nuget/v/ReactiveMarbles.ObservableEvents.SourceGenerator.svg
18+
19+
## What does it do?
20+
21+
ObservableEvents generator will convert events within an assembly and create observable wrappers for them.
22+
23+
It is based on pharmacist [Pharmacist](https://github.com/reactiveui/Pharmacist) and uses .NET Source Generator technology.
24+
25+
## Installation
26+
Include the following in your .csproj file
27+
28+
```xml
29+
<PackageReference Include="ReactiveMarbles.ObservableEvents.SourceGenerator" Version="1.0.2" PrivateAssets="all" />
30+
```
31+
32+
The `PrivateAssets` will prevent the ObservableEvents source generator from being inherited by other projects.
33+
34+
## How to use
35+
36+
### Instance Based
37+
It injects a class for instance based events into your source code which will expose a extension method called `Events()`.
38+
39+
You need to include the namespace `ReactiveMarbles.ObservableEvents` to access to the extension method.
40+
41+
You can then use this to get `IObservable<T>` instances from your events.
42+
43+
```cs
44+
using ReactiveMarbles.ObservableEvents;
45+
46+
public void MyClass : INotifyPropertyChanged
47+
{
48+
// Assumes this belong in a class with a event called PropertyChanged.
49+
public void RunEvents()
50+
{
51+
this.Events().PropertyChanged.Subscribe(x => Console.WriteLine($"The {x} property has changed"));
52+
}
53+
54+
public event PropertyChangedEventHandler PropertyChanged;
55+
}
56+
```
57+
58+
### Static Events
59+
60+
You must use include a attribute `GenerateStaticEventObservables` on the assembly level for a particular class. This will generate a class `RxEvents` in the same namespace as the specified class.
61+
62+
```cs
63+
[assembly: GenerateStaticEventObservablesAttribute(typeof(StaticTest))]
64+
65+
public static class StaticTest
66+
{
67+
public static event EventHandler? TestChanged;
68+
}
69+
```

0 commit comments

Comments
 (0)