In Depth Banner
Skip Navigation Links

Select your preferred language

The FilterablePropertyBase class which implements ICustomTypeDescriptor.

  public class FilterablePropertyBase : ICustomTypeDescriptor

  {

 

    protected PropertyDescriptorCollection GetFilteredProperties(Attribute[] attributes)

    {

      PropertyDescriptorCollection pdc = TypeDescriptor.GetProperties(this,attributes,true);

      PropertyDescriptorCollection finalProps = new PropertyDescriptorCollection(new PropertyDescriptor[0]);

 

      foreach(PropertyDescriptor pd in pdc)

      {

        bool include=false;

        bool Dynamic=false;

        foreach(Attribute a in pd.Attributes)

        {

          if(a is DynamicPropertyFilterAttribute)

          {

            Dynamic=true;

 

            DynamicPropertyFilterAttribute dpf=(DynamicPropertyFilterAttribute)a;

            PropertyDescriptor temp=pdc[dpf.PropertyName];

            if(dpf.ShowOn.IndexOf(temp.GetValue(this).ToString())>-1)

            {

              include=true;

            }

          }

        }

        if(!Dynamic || include)

          finalProps.Add(pd);

      }

      return finalProps;

    }

    

    #region ICustomTypeDescriptor Members

 

    public TypeConverter GetConverter()

    {

      return TypeDescriptor.GetConverter(this,true);

    }

 

    public EventDescriptorCollection GetEvents(Attribute[] attributes)

    {

      return TypeDescriptor.GetEvents(this,attributes,true);

    }

 

    EventDescriptorCollection System.ComponentModel.ICustomTypeDescriptor.GetEvents()

    {

      return TypeDescriptor.GetEvents(this,true);

    }

 

    public string GetComponentName()

    {

      return TypeDescriptor.GetComponentName(this,true);

    }

 

    public object GetPropertyOwner(PropertyDescriptor pd)

    {

      return this;

    }

 

    public AttributeCollection GetAttributes()

    {

      return TypeDescriptor.GetAttributes(this,true);

    }

 

    public PropertyDescriptorCollection GetProperties(Attribute[] attributes)

    {

      return GetFilteredProperties(attributes);

    }

 

    PropertyDescriptorCollection System.ComponentModel.ICustomTypeDescriptor.GetProperties()

    {

      return GetFilteredProperties(new Attribute[0]);

    }

 

    public object GetEditor(Type editorBaseType)

    {

      return TypeDescriptor.GetEditor(this,editorBaseType,true);

    }

 

    public PropertyDescriptor GetDefaultProperty()

    {

      return TypeDescriptor.GetDefaultProperty(this,true);

    }

 

    public EventDescriptor GetDefaultEvent()

    {

      return TypeDescriptor.GetDefaultEvent(this,true);

    }

 

    public string GetClassName()

    {

      return TypeDescriptor.GetClassName(this,true);

    }

 

    #endregion

  }

 

Use the Back button to return to the article.

Copyright © Bob Powell 2003-2009. All rights reserved