My aging dasBlog install got hacked last night some time... by the turks ;o) all back up and running again now, upgraded to dasBlog 1.9 as well... might migrate to a different blog platform at some point (either Subtext, or I might give nBlogr a whirl because I know the technology stack it sits on reasonably well.
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();
I've been under whelmed with GoogleGears & GoogleReader as a combination (though it has enabled search capabilities for the last 2000 posts to GoogleReader which is a god send)...
But what I was thinking of that would be particularly useful in offline mode, a wiki... I wonder if it'll ever happen?
So I've been mulling some ideas over after the whole abusing
lambdas for Hash table construction (here
and here) ... and after reading a post on Jb
Evain's blog I decided to create a little bit of code for
doing annotations... so given a class say:
public class ClassA
{
public int Id { get; set; }
public string Name { get; set; }
}
You can then do this kind of thing (assuming you've added the
apropriate namespace where the Annotations static class
resides in)
Under the hood the values are stored against a dictionary where
the keys (in this case the instance of classA) are weak
referenced... so once classA is garbage collected the entries in
the dictionary will also dissapear in time (next time any method
touches the dictionary).
The nice thing is obviously you can directly interogate the
Annotations static class itself with a query expression to say
find all objects with a certain annotation.
So, I got a comment on the last post about hashesfrom
lambdas (from Andrey
Shchekin)... It pointed out the fact that you don't need to
use expressions at all... which hilights an observation that I
hadn't made myself - such that the lambda parameter
names are available in the generated delegate... which of
course makes perfect sense!
So given:
Func func = Name => "Value";
You can get the lambda parameter "Name" from the function
delegate by calling: