This custom tool will generate a partial class file implementing INotifyPropertyChange as well as a strongly-typed event for each property declared in the file it's applied to.
This is very useful when creating models or entities that are used in data-binding scenarios, and where an associated presenter needs to perform certain logic when a given property changes.
Communicating through these strong-typed events prevents tight coupling between the presenter and the UI, which now communicate exclusively through the model/data context.
A must-have for anyone doing "Binding Oriented Programming"
The code generator solves the problem of having the presenter attach to the generic INotifyPropertyChanged.PropertyChanged event and checking the property by name, which must be kept in sync with the class definition and doesn't participate in refactorings.
It will also solve the initialization sequence and validation (post deserialization and afterwards) problem by implementing ISupportInitialize, ISupportInitializeNotification and IChangeTracking, which allows it to track changes automatically on its members and nested values. The public interface of your object remains uncluttered by implementing most of these privately. The data context class can simply call EnsureInitialized
at the beginning of each method call to make sure that the class has been properly initialized, and that if it's dirty, it's re-validated.
A DoValidate method is added to the main class to implement the actual property validation (where you could use the Standalone Validation Block
for example), as well as RaiseXXChanged method calls on each property setter, and a DoInitialize to perform custom initialization logic that should happen after validation.
Finally, the generated code doesn't depend on anything other than System.ComponentModel, so WPF is not even required to use the codegen for other data-binding scenarios (WinForms should work fine).
Installation: run the MSI, or compile the included solution.
Usage: assign the value DataBinding to any code file in VS. A corresponding file ending in ".DataBinding.cs" (or .vb) will be generated automatically everytime the main file changes.
This release supports both VB and C# (both 2.0 and 3.5), VS2005 and VS2008, as well as full unit tests for the generated code. It also supports inheritance between models, which changes the generated code to hook into the virtuals provided by the generator for the base class.