user3732793
user3732793

Reputation: 1959

Enum GetCustomAttributes does not show anything

in this simple class I try to overwrite ToString() to show all custom Attributes.

public class TryMe
{
    public TryMe(int id, List<String> tests)
    {
        ID = id;
        Tests = tests;
    }
    public int ID { get; set; }
    public List<String> Tests { get; set; }

    public override string ToString()
    {
        string me = "";
        var attributes = this.GetType().GetCustomAttributes();

        foreach (var attribute in attributes)
        {
            me = me + attribute.ToString() + ",";
        }
        return me;
    }
}

It doesn't show any value or error.

Aren't ID and Tests custom attributes ? Is there any easy enumeration if the class becomes bigger ?

Upvotes: 0

Views: 114

Answers (1)

faso
faso

Reputation: 697

Attributes are things like there:

[MyCoolAttribute]
public MyCoolMethod()

What you're looking for are Properties

this.GetType().GetProperties()

Upvotes: 5

Related Questions