I have been looking for an example of how to get a property's value from within a custom attribute's code.
Example for illustration purposes only: We have a simple book class with only a name property. The name property has a custom attribute:
public class Book { [CustomAttribute1] property Name { get; set; } } Within the custom attribute's code, I would like to get the value of the property on which the attribute has been decorated:
public class CustomAttribute1: Attribute { public CustomAttribute1() { //I would like to be able to get the book's name value here to print to the console: // Thoughts? Console.WriteLine(this.Value) } } Of course, "this.Value" does not work. Any thoughts?