C# Get memberinfo for custom attribute's target

Posted by Waldo Bronchart on Stack Overflow See other posts from Stack Overflow or by Waldo Bronchart
Published on 2011-01-28T22:37:56Z Indexed on 2011/01/28 23:26 UTC
Read the original article Hit count: 165

Filed under:
|

Given a custom attribute, I want to get the name of its target:

public class Example
{
    [Woop] ////// basically I want to get "Size" datamember name from the attribute
    public float Size;
}

public class Tester
{
    public static void Main()
    {
        Type type = typeof(Example);
        object[] attributes = type.GetCustomAttributes(typeof(WoopAttribute), false);

        foreach (var attribute in attributes)
        {
            // I have the attribute, but what is the name of it's target? (Example.Size)
            attribute.GetTargetName(); //??
        }
    }
}

Hope it's clear!

© Stack Overflow or respective owner

Related posts about c#

Related posts about reflection