Just an alternative answer; if you want the performance, but a similar API - consider HyperDescriptor; this uses Reflection.Emit
underneath (so you don't have to), but exposes itself on the PropertyDescriptor
API, so you can just use:
PropertyDescriptorCollection props = TypeDescriptor.GetProperties(obj);
props["Name"].SetValue(obj, "Fred");
DateTime dob = (DateTime)props["DateOfBirth"].GetValue(obj);
One line of code to enable it, and it handles all the caching etc.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…