I am declaring the custom attribute that accept its property type. For example, let my attribute name as MyCustomAttribute
, then
public class MyCustomAttribute : Attribute
{
public Type PropertyType { get; }
public MyCustomAttribute(Type propertyType)
{
PropertyType = propertyType;
}
}
And its usage is
enum Gender
{
Male,
Female
}
[MyCustom(typeof(Gender))]
public Gender Gender { get; set; }
I want to know that is there a way that pass the property type automatically in C#. Like CallerMemberNameAttribute
in RaisePropertyChanged implementation, can I register an attribute like the below code?
[MyCustom()] // typeof(Gender) is omitted
public Gender Gender { get; set; }