Venn 1.3.0
dotnet add package Venn --version 1.3.0
NuGet\Install-Package Venn -Version 1.3.0
<PackageReference Include="Venn" Version="1.3.0" />
<PackageVersion Include="Venn" Version="1.3.0" />
<PackageReference Include="Venn" />
paket add Venn --version 1.3.0
#r "nuget: Venn, 1.3.0"
#:package Venn@1.3.0
#addin nuget:?package=Venn&version=1.3.0
#tool nuget:?package=Venn&version=1.3.0
Venn
The Venn project is a set of tools for working with WPF applications. It was initially born as a collection of extension methods, but is evolving into something more complex.
NotifyPropertyChangedWrapper
The NotifyPropertyChangedWrapper<T> class is designed to wrap an object that does not implement the INotifyPropertyChanged interface. It facilitates the notification of property changes for the wrapped object by exposing an observable stream that emits events whenever a property changes.
Class Overview:
- Generic Type
T: Represents the type of the object that the class wraps. - Constructor: Initializes a new instance of the class with an initial value for the wrapped object.
- Observable Property: Provides an observable stream (
IObservable<T>) that emits events whenever a property of the wrapped object changes. - Value Property: Gets or sets the value of the wrapped object. If the value changes, the class triggers the PropertyChanged event and notifies observers through the observable stream.
- PropertyChanged Event: Event that is triggered when a property of the wrapped object changes.
Usage:
- Initialization: Create an instance of
NotifyPropertyChangedWrapper<T>by providing an initial value for the wrapped object.var wrapper = new NotifyPropertyChangedWrapper<int>(initialValue);
WhenAny methods
Venn provides you WhenAny methods that allow you to observe INotifyPropertyChanged objects. WhenAny methods return an IObservable to which you can subscribe and perform necessary actions.
The NotifyPropertyChangedExtensions class provides extension methods for enabling observable property change notifications on objects that implement the INotifyPropertyChanged interface or use the NotifyPropertyChangedWrapper<T> class.
Method Overview:
WhenAny<T, TProperty>Method for Objects ImplementingINotifyPropertyChanged:- Parameters:
source: The object implementingINotifyPropertyChangedon which to observe property changes.propertySelector: An expression specifying the property to observe changes for.
- Returns:
- An observable stream (
IObservable<TProperty>) that emits events whenever the specified property changes.
- An observable stream (
- Usage Example:
var disposables = new CompositeDisposable(); var observable = myObject.WhenAny(obj => obj.MyProperty); observable.Subscribe(newValue => { // Handle property change }) .DisposeWith(disposables); //add an `IDisposable` object to a `CompositeDisposable`
- Parameters:
WhenAny<T, TProperty>Method forNotifyPropertyChangedWrapper<T>:- Parameters:
source: An instance of theNotifyPropertyChangedWrapper<T>class on which to observe property changes.propertySelector: An expression specifying the property to observe changes for.
- Returns:
- An observable stream (
IObservable<TProperty>) that emits events whenever the specified property changes.
- An observable stream (
- Usage Example:
var disposables = new CompositeDisposable(); var wrapper = NotifyPropertyChangedWrapper<T>.Wrap(myObject); var observable = wrapper.WhenAny(obj => obj.MyProperty); observable.Subscribe(newValue => { // Handle property change }) .DisposeWith(disposables); //add an `IDisposable` object to a `CompositeDisposable`
- Parameters:
WhenAny<T>Method forNotifyPropertyChangedWrapper<T>(No Property Selector):- Parameters:
source: An instance of theNotifyPropertyChangedWrapper<T>class on which to observe any property changes.
- Returns:
- An observable stream (
IObservable<T>) that emits events whenever any property changes.
- An observable stream (
- Usage Example:
var disposables = new CompositeDisposable(); var wrapper = NotifyPropertyChangedWrapper<T>.Wrap(myObject); var observable = wrapper.WhenAny(); observable.Subscribe(newValue => { // Handle any property change }) .DisposeWith(disposables); //add an `IDisposable` object to a `CompositeDisposable`
- Parameters:
DisposeWith Method for Dispose Management
Venn provides you with a DisposeWith extension method that simplifies the management of disposable resources. This method allows you to add an IDisposable object to a CompositeDisposable, facilitating the coordinated disposal of multiple objects.
Method Overview:
DisposeWithMethod:- Signature:
public static IDisposable DisposeWith(this IDisposable disposable, CompositeDisposable compositeDisposable) - Parameters:
disposable(type:IDisposable): The object to be added to thecompositeDisposable.compositeDisposable(type:CompositeDisposable): The container of disposable objects.
- Exceptions:
ArgumentNullException: Thrown ifdisposableorcompositeDisposableis null.
- Returns:
- The original
IDisposableobject.
- The original
- Usage Example:
var disposableObject = //... create your IDisposable object var compositeDisposable = new CompositeDisposable(); // Add the IDisposable object to the CompositeDisposable using DisposeWith disposableObject.DisposeWith(compositeDisposable); // Dispose of all IDisposable objects in the CompositeDisposable when needed compositeDisposable.Dispose();
- Signature:
Important Notes:
- The
DisposeWithmethod is particularly useful when you want to manage the disposal of multiple objects in a coordinated manner. - Ensure that the object and the
CompositeDisposableare not null before using this method to prevent potential null reference exceptions. - Dispose of the
CompositeDisposablewhen it's appropriate to release the resources held by the disposable objects.
This extension method follows a similar pattern to the WhenAny methods, providing a clean and concise way to handle the disposal of disposable resources.
Important Notes:
- These extension methods simplify the process of observing property changes using reactive programming and can be particularly useful in scenarios where real-time updates are required based on property modifications.
- Ensure that the object or wrapper instance is not null before using these methods to prevent potential null reference exceptions.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- Microsoft.CodeAnalysis (>= 4.5.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Logging (>= 8.0.0)
- Microsoft.Maui.Controls (>= 8.0.14)
- System.ComponentModel (>= 4.3.0)
- System.Reactive (>= 6.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.3.0 | 247 | 5/20/2024 |
| 1.3.0-beta | 169 | 3/27/2024 |
| 1.2.0 | 264 | 12/28/2023 |
| 1.1.0 | 246 | 8/3/2023 |
| 1.0.0 | 352 | 10/8/2022 |