mscottford (owner)

Revisions

gist: 126074 Download_button fork
public
Description:
Object helper method that makes it quite a bit easier to work with anonymous classes.
Public Clone URL: git://gist.github.com/126074.git
Embed All Files: show embed
ObjectExtensions.cs #
1
2
3
4
5
6
7
8
9
10
11
12
// Example
// var sample = new { booleanValue = true, stringValue = "Test Value" }
// sample.Property<bool>("booleanValue") will result in true
// sample.Property<string>("stringValue") will result in "Test Value"
static class ObjectExtensions
{
    public static T Property<T>(this object target, string name)
    {
        return (T)target.GetType().InvokeMember(name, BindingFlags.GetProperty, null, target, new object[] { });
    }
}