I wanted to be able to add properties on the fly.%A0 I've changed the idea a bit to look them up on the fly versus adding them.%A0 Using psuedo-code:
// expandable object
MyObject o = new MyObject();
// add the property
o.AddProperty("FirstName", "Justin");
I'm not using these properties in code anywhere.%A0 I'm actually feeding the object to a template system (the C# port of StringTemplate%A0in this case).%A0 Now StringTemplate supports reading properties in the templates like so...
$p.FirstName$
But unfortunately the%A0MyObject%A0type%A0doesn't have a FirstName property.%A0 And StringTemplate uses the Type to do reflection.%A0 Anyway, during my research of IExpando (much like IDispatchEx), I noticed the interface IReflect.%A0 Looking at the docs for it, it contains all the most common methods that people use on Type when performing reflection (GetProperty, GetMethod, etc.).%A0 So if I change StringTemplate to use IReflect vs. the Type class, then I could implement IReflect myself.%A0 Of course, there are problems with this; mainly the fact that PropertyInfo is an abstract class (MemberInfo, the parent class, is also abstract).%A0 So I would have to write implementations of those.
Hm...this seems like more effort than its worth.%A0 Maybe I should just do something like this...
$p.Attributes.FirstName
Attributes would be an IDictionary.%A0 Then I can extend StringTemplate to look at the object.%A0 If it is IDictionary, then use the property name as the key.%A0 The former definitely has more of a "coolness" factor, but the latter would take like 15 minutes.
Heh. As opposed to the following in Smalltalk: