Reputation: 1959
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
Reputation: 697
Attributes are things like there:
[MyCoolAttribute]
public MyCoolMethod()
What you're looking for are Properties
this.GetType().GetProperties()
Upvotes: 5