I have a certain object and I want to do something with all its fields that have some attribute defined on them.
Is there a way to know on which field the attribute is defined?
For example something like this:
the class:
internal class Student
{
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
[Degree]
public int StartYear { get; set; }
[Degree]
public int Avg { get; set; }
[Degree]
public int Courses { get; set; }
public Student(int id, string firstName, string lastName, int startYear, int avg, int courses)
{
Id = id;
firstName = firstName;
lastName = lastName;
startYear = startYear;
Avg = avg;
Courses = courses;
}
}
attribute:
public class Degree : Attribute
{
public string MSG { get; set; }
public Degree()
{
MSG = "I have degree attribute";
}
}
main:
Student s = new Student(1, "example", "example", 2000, 99, 5);
How can I know about each field in s
what are the attributes defined on it?