Growcode is an open-source program for producing object models for the .NET platform.

Given a set of simple C#-style class definitions, Growcode will produce a .NET assembly containing those classes enhanced with the following features:

  • Consistent event mechanism for changes to fields of objects
  • Undo/redo support for all changes to the object model
  • Serialization of the model to and from XML
  • Double dispatch support for polymorphic operations

Growcode supports defining both classes and enumerations. Data types supported include:

  • All C# built-in types or their equivalent .NET types
  • List<T> exposed through an interface providing event notification
  • Dictionary<K, V> also exposed with events
  • DateTime, TimeSpan and Guid

Quickstart example

This example shows how a simple set of class definitions enhanced by Growcode can be used in a natural way while providing easy access to the advanced features of the object model, such as events and undo/redo:

Given the two simple class definitions below:

    class Company
        string Name;
        List<Employee> Employees;
    class Employee
        string Name;
        int Salary = -1;

A .NET assembly is produced by Growcode containing enhanced versions of the classes.

Assuming a company is created like this:

    Company company = new Company("X Inc");

All objects in the model can be watched for changes. For example, to print the names of employees as they are added to the company object, this code could be used:

    company.Employees.ItemsAdded += delegate(ModelItem sender,
                                             ListItemsAddedEventArgs<Employee> args)
        foreach (Employee employee in args.ItemsAdded)

Or to watch for changes to a specific value, such as the companies name:

    company.NameChanged += delegate(ModelItem sender, ItemChangedEventArgs<string> args)
        Console.WriteLine("Company name changed from " + args.OldItem + " to " + args.Item);

Company is the root of the model (because Employee is referenced by Company), so is enhanced with undo/redo capabilities, making code like this possible:

    company.Name = "Y Inc";

Multiple Changes to an object model can be made in a single transaction by using a change set:

    using(IAutoChangeSet auto = company.AutoChangeSet("Change name and add employee"))
        company.Name = "Z Inc";
        company.Employees.Add(new Employee("Joe"));

If Commit had not been called, or an exception was thrown inside the using statement's scope before Commit was called then the object model would be unaffected by any changes made within the using statement's scope.

You may notice Employee only takes the employee's name on construction and not the employee's salary, this is because any members given an initial value in the class definition do not appear on the generated constructor.

If Undo is now called on the Company object, both changes made in the using statement will be undone at once:

    Debug.Assert(company.Name == "Y Inc" && company.Employees.Count == 0);
    Debug.Assert(company.Name == "Z Inc" && company.Employees.Count == 1);

Growcode has many more features, notably support for inheritance and double dispatch. Please see the Manual for more information.