Annotations - here's the code

Here's the code for my last post on Annotations - I tidied up a few things up (it's still very basic but it does work) there's a single test fixture to give you a guide for usage... so things like:

    [Test]
public void QueryStoreForClassAnnotationsWithCertainKey()
{
ClassA target1 = new ClassA();
ClassA target2 = new ClassA();
ClassA target3 = new ClassA();
target1.Annotate(Description => "class number 1");
target2.Annotate(Description => "class number 2");
target3.Annotate(Parsed => true);

var results = AnnotationStore.Classes
.Where(a => a.HasKey("Description"))
.ToList();

Assert.AreEqual(2, results.Count);
}

And also the equivalent thing is possible for members... though I suspect annotating members isn't all that useful in most cases...

  [Test]
public void QueryStoreForMemberAnnotations()
{
ClassA target1 = new ClassA();
ClassA target2 = new ClassA();
ClassA target3 = new ClassA();

target1.Annotate(() => target1.FirstName,
CamelCase => true); // annotating a property
target1.Annotate(() => target1.Field,
Ignored => true); // annotating a field
target2.Annotate(() => target2.Execute(),
Parsed => true); // annotating a method
target3.Annotate(Parsed => true);

var results = AnnotationStore.Members
.Where(p => p.HasKey("CamelCase"))
.ToList();

Assert.AreEqual(1, results.Count);
}

Written on June 14, 2007