mercredi 10 février 2016

Custom Attribute on property in C#

I have a class Person with two properties

public sealed class Person
{
[Description("This is the first name")]
public string FirstName { get; set; }
[Description("This is the last name")]
public string LastName { get; set; }
}

In my console application code I'd like to get for each property of each instance the value of the Description Attribute.....

something similar to

Person myPerson = new Person();
myPerson.LastName.GetDescription() // method to retrieve the value of the attribute

Is it possible to do this task? Can someone suggest me a way? Best regards Fab





Aucun commentaire:

Enregistrer un commentaire