0
Answer

How do I get the name of a property that I have a custom attribute on?

Brett

Brett

14y
2.2k
1

Hello,

Basically I have this custom attribute and one of the properties in the attribute is Name for if you want to change the name of the property that the attribute is attached too. By default I want the attribute to use the name that the property already has if I they don't care to set the name. How do I do this? Do I use reflection?

   public partial class User : UserBase

    {

        [Filter()]

        public string FriendlyName { get; set; }

    }

So I want to get 'FriendlyName' and stick it into my FilterProperty:

  

   
 
 [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = false)]

    public class FilterAttribute : Attribute

    {

        private bool isFilterable;

        private string filterName;

        public FilterAttribute()

        {

            isFilterable = true;
            filterName = ???

        }