Brett

Brett

  • NA
  • 5
  • 0

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

Jan 26 2010 3:54 PM

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 = ???

        }