Project Description

A C# .NET Library to simplify M-V-VM (Model, View, Viewmodel) programming. Includes base implementations for observable objects (property change notifications), weak delegates/events and asynchronous and synchronized events, efficient event handling, disposable base, etc.

Nuget: PM> Install-Package SharpObservation


Sharp Observation fulfills the following goals:
  • A high-performance implementation for exposing events:
    • A performance optimized EventHandlerList reduces memory footprint of event objects - objects retains a very small footprint when events aren't hooked up, and are performant when event handlers are attached.
    • Type safe / signature safe pattern for raising events.
Read more about implementing efficient event-raising classes
  • A base implementation of the observable pattern, including:
    • INotifyPropertyChanged and INotifyPropertyChanging implementation.
    • A richer PropertyChangedEventArgs which enable undo scenarios.
    • A bypass mechanism to property change optimize performance when no listeners are attached.
    • An IsNotifcationActive property which expresses whether any listeners are attached.
    • An IsNotifcationActiveChanged event which fires when IsNotifcationActive changes.
    • A helper type to simplified implementation of CLR properties.
Read more about observable objects
  • Extension methods to convert delegates to become:
    • Synchronized - i.e. the delegate raises it's target on an appropriate thread
    • Asynchronous - i.e. the delegate does not wait for the target to complete before returning.
How to use synchronized events
How to use asynchronous events
  • Provides a base implementation of the auto-dispose pattern:
    • all private fields with references to objects are nulled (and optionally disposed) upon disposal.
    • an IsDisposed property, allowing blind callers to detect whether the instance has been disposed.
    • ThrowIfDisposed() for guarding against method calls after disposal.
  • A helper class - DisposeHelper - which generates efficient IL code for disposing of objects:
    • Correctly implements the IDisposable pattern.
    • If the instance is being disposed (as opposed to finalized), then it disposes of any objects referenced by fields, and those fields are assigned null.
    • Nulls references to large objects (like arrays).
    • If the class contains a boolean field named "isDisposed" (case insensitive), then the field is set to true.
    • If the class contains an Action field named "throwIfDisposed" (case insensitive), then the delegate is assigned to a method that throws ObjectDisposedException.
    • If (and only if) the class contains a finalizer, then GC.SurpressFinalize is called to remove the object from the finalization queue.

Last edited Fri at 4:21 PM by maranite, version 18