<p>I have a class which is marked with a custom attribute, like this:</p>

<pre><code>public class OrderLine : Entity
{
    ...
    [Parent]
    public Order Order { get; set; }
    public Address ShippingAddress{ get; set; }
    ...
}
</code></pre>

<p>I want to write a generic method, where I need to get the Property on a Entity which is marked with the  Parent attribute.</p>

<p>Here is my Attribute:</p>

<pre><code>[AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = false)]
public class ParentAttribute : Attribute
{
}
</code></pre>

<p>How do I write this?</p>

This works for me:
```
```
public static object GetParentValue<T>(T obj) {
    Type t = obj.GetType();
    foreach (var prop in t.GetProperties()) {
        var attrs = prop.GetCustomAttributes(typeof(ParentAttribute), false);
        if (attrs.Length != 0)
            return prop.GetValue(obj, null);
    }

    return null;
}
```
```