This project is read-only.
When we are setting up a mapping, we also want to make sure that changes in the types we map between is detected and updated in the mapping. A good example is when a property is added later, after we have set up the mapping, and this property does not get related in the mapping because we forgot to change the mapping when we made the change. Glue helps you against these problems.

Given these two types:

class DomainPerson { public String FirstName { get; set; } }
class GuiPerson { public String FirstName { get; set; } }

And this mapping:

var mapping = new Mapping<DomainPerson, GuiPerson>();
mapping.Relate(domain => domain.FirstName, gui => gui.FirstName);

All the properties (currently only "FirstName") on DomainPerson is now mapped. When you relate between types you go through all properties and decide how to map them (or if you want to ignore them). Now we have decided the mapping for all DomainPerson's properties. We can then assert it, writing this in a test:


Now, if someone in the future adds a property to DomainPerson without doing something with it in the Mapping, and then runs this test, the code will throw an exception telling you what properties are not related.

Ignoring properies

But what if you do not want to relate a property and you still want to verify that you have made a decision for that property (so the verification-method does not give an exception). Then you simply tell the mapping to ignore it, like this:

mapping.IgnoreTowards<GuiPerson>(x => x.FirstName);

This tells the verifier that although the FirstName-property on GuiPerson isn't related to anything, it is still considered, and it should not result in an exception.

Also note that if you try to ignore a property that is already related, an exception will be thrown.

mapping.Relate(domain => domain.FirstName, gui => gui.FirstName);
Assert.Throws(typeof(GlueException), () => mapping.IgnoreTowards<DomainPerson>(x => x.FirstName));

Note: If you have flattened relations (where you add a new mapping) these mappings will also be checked

Last edited Sep 21, 2009 at 8:03 PM by ToreVestues, version 5


No comments yet.