Relationship Manager in C#

This is a completely rewritten version of Relationship Manager, which runs 16x faster in some cases.  It has a little bit of caching in it too, to enhance performance.


UML for the new, fast C# version of Relationship Manager


In your project, add references to


and in your code add the using clauses:

using RelationshipManager.Interfaces;
using RelationshipManager.Turbo;


Here is the API

interface IRelationshipManager

        void AddRelationship(object fromObj, object toObj, string relId);
        void AddRelationship(object fromObj, object toObj);
        void EnforceRelationship(string relId, Cardinality cardinality);
        void EnforceRelationship(string relId, Cardinality cardinality, Directionality directionality);
        IList FindObjectsPointedToByMe(object fromObj, string relId);
        object FindObjectPointedToByMe(object fromObj, string relId);
         IList FindObjectsPointingToMe(object toObj, string relId);
        object FindObjectPointingToMe(object toObj, string relId);
        void RemoveRelationship(object fromObj, object toObj, string relId);
        void RemoveAllRelationshipsInvolving(object obj, string relId);
        int Count();
        int CountRelationships(string relId);
        void Clear();
        bool DoesRelIdExistBetween(object fromObj, object toObj, string relId);
        IList FindRelIdsBetween(object fromObj, object toObj);


    public enum Cardinality

    public enum Directionality

See Usage for more help.

Example 1

private IRelationshipManager rm;

rm = new RelationshipMgrTurbo();

rm.AddRelationship('a', 'b', "rel1");

IList list = rm.FindObjectsPointedToByMe('a', "rel1");

Assert.AreEqual(list[0], 'b');

Example 2

private IRelationshipManager rm;

rm = new RelationshipMgrTurbo();

rm.AddRelationship('a', 'b', "rel1");

rm.AddRelationship('a', 'c', "rel1");

rm.AddRelationship('a', 'z', "rel2");

IList list;

list = rm.FindObjectsPointedToByMe('a', "rel1");

char[] expected = {'b', 'c'};

Assert.AreEqual(list.ToString(), new ArrayList(expected).ToString());

list = rm.FindObjectsPointedToByMe('a', "rel2");

Assert.AreEqual(list[0], 'z');

Other examples

Study the unit tests to see how to drive this.  Open the project
     ...\Turbo RM Source and Tests - VS2005\Turbo RM Solution.sln


Download Source code and DLLs

Download this zip and run in Visual Studio 2008.  There are a number of directories but you really only need the two dll's out of
    ...\RelationshipManager56\Turbo RM Source and Tests - VS2005\Relationship Manager Turbo\bin\Debug

Relationship Manager Interfaces.dll
Relationship Manager Turbo.dll

You can open the solution
   Turbo RM Source and Tests - VS2005/Turbo RM Solution.sln
to compile and run one set of tests.

There are other projects in this zip which are boo unit tests and the boo implementation.  I'm going to organise and document it a bit better soon.