Venn 1.3.0

dotnet add package Venn --version 1.3.0
                    
NuGet\Install-Package Venn -Version 1.3.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Venn" Version="1.3.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Venn" Version="1.3.0" />
                    
Directory.Packages.props
<PackageReference Include="Venn" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Venn --version 1.3.0
                    
#r "nuget: Venn, 1.3.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Venn@1.3.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Venn&version=1.3.0
                    
Install as a Cake Addin
#tool nuget:?package=Venn&version=1.3.0
                    
Install as a Cake Tool

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:

  1. 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:

  1. WhenAny<T, TProperty> Method for Objects Implementing INotifyPropertyChanged:

    • Parameters:
      • source: The object implementing INotifyPropertyChanged 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.
    • 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`
      
  2. WhenAny<T, TProperty> Method for NotifyPropertyChangedWrapper<T>:

    • Parameters:
      • source: An instance of the NotifyPropertyChangedWrapper<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.
    • 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`
      
  3. WhenAny<T> Method for NotifyPropertyChangedWrapper<T> (No Property Selector):

    • Parameters:
      • source: An instance of the NotifyPropertyChangedWrapper<T> class on which to observe any property changes.
    • Returns:
      • An observable stream (IObservable<T>) that emits events whenever any property changes.
    • 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`
      

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:

  1. DisposeWith Method:
    • Signature:
      public static IDisposable DisposeWith(this IDisposable disposable, CompositeDisposable compositeDisposable)
      
    • Parameters:
      • disposable (type: IDisposable): The object to be added to the compositeDisposable.
      • compositeDisposable (type: CompositeDisposable): The container of disposable objects.
    • Exceptions:
      • ArgumentNullException: Thrown if disposable or compositeDisposable is null.
    • Returns:
      • The original IDisposable object.
    • 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();
      

Important Notes:

  • The DisposeWith method is particularly useful when you want to manage the disposal of multiple objects in a coordinated manner.
  • Ensure that the object and the CompositeDisposable are not null before using this method to prevent potential null reference exceptions.
  • Dispose of the CompositeDisposable when 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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