Attributes are metadata applied to members of a type, the type itself, method parameters, or the assembly. For you to have access to the metadata, you must have had the original member itself to user GetCustomAttributes
etc, i.e. your instance of Type
, PropertyInfo
, FieldInfo
etc.
In your case, I would actually pass the name of the property to the attribute itself:
public CustomAttribute : Attribute
{
public CustomAttribute(string propertyName)
{
this.PropertyName = propertyName;
}
public string PropertyName { get; private set; }
}
public class MyClass
{
[Custom("MyProperty")]
public int MyProperty { get; set; }
}