[MyAttribute()]
public string Name { get; set; }
In MyAttribute
I need to know the name of associated property, is it possible?
EDIT:
I need to use it in text formatting.
No, this is not possible. Usually you would use reflection to read attributes applied on a given property, so you already know the property. Example:
var properties = typeof(SomeType).GetProperties();
foreach (var property in properties)
{
var attributes = property.GetCustomAttributes(typeof(MyAttribute), true);
if (attributes.Count > 0)
{
// look at property.Name here
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With