Take this sample class as an example:
[AttributeUsage(AttributeTargets.All, AllowMultiple=true)]
public class BugFixAttribute : System.Attribute
{
public int BugId { get; private set; }
public string Programmer { get; private set; }
public DateTime Date { get; private set; }
public string Comments { get; set; }
public string RefersTo { get; set; }
public BugFixAttribute(int bugId = 0, string programmer = "")
{
this.BugId = bugId;
this.Programmer = programmer;
Date = DateTime.Now;
}
}
And I want to recuse through the properties to use like:
object[] attr = info.GetCustomAttributes(typeof(BugFixAttribute), false);
foreach (object attribute in attr)
{
BugFixAttribute bfa = (BugFixAttribute) attribute;
Debug.WriteLine(string.Format("\nBugId: {0}", bfa.BugId));
Debug.WriteLine(string.Format("Programmer: {0}", bfa.Programmer));
//...
}
Because what I need to do is to print these to a file. So how can I recurse through the properties instead of doing the Debug.WriteLine()
through all of them, is there a way or do I have to write it out.