I've got a property contained in a class for example
public class Greeter {
private Hashtable _data;
public string HelloPhrase { get; set; }
public Greeter(data) {
_data = data;
}
}
What I would like to do is add an Attribute to the HelloPhrase property, like this
[MyCustomAttribute("Hello_Phrase")]
public string SayHello { get; set; }
Such that during the constructor I can reflect over the Properties in the Class(Greeter) where MyCustomAttribute has been defined and set the Get/Set methods of the property to an anonymous method / delegate.
public Greeter(data) {
_data = data;
ConfigureProperties();
}
I've managed to get the PropertyInfo's from the class but this only exposes GetSetMethod (http://msdn.microsoft.com/en-us/library/system.reflection.propertyinfo.getsetmethod.aspx) and the corresponding GetGetMethod.
I've read through some of the questions here and online but can't find an answer that doesn't use an Aspects library of some sort.
Could anyone provider pointers to setting the Get/Set methods at runtime? Ideally to a delegate like
x =>_data[keyDefinedByAttribute];