In Depth Banner
Skip Navigation Links

Select your preferred language

The FriendlyNamePropertyDescriptor

Note how every proprty is overridden to return the corresponding data from the PropertyDescriptor handed in in the constructor. The exception being the DisplayName property.

  public class FriendlyNamePropertyDescriptor : PropertyDescriptor

  {

    private PropertyDescriptor basePropertyDescriptor;

 

    public FriendlyNamePropertyDescriptor(PropertyDescriptor pd) : base(pd)

    {

      this.basePropertyDescriptor=pd;

    }

 

    public override void AddValueChanged(object component, EventHandler handler)

    {

      this.basePropertyDescriptor.AddValueChanged (component, handler);

    }

 

    public override AttributeCollection Attributes

    {

      get

      {

        return this.basePropertyDescriptor.Attributes;

      }

    }

 

    public override bool CanResetValue(object component)

    {

      return this.basePropertyDescriptor.CanResetValue(component);

    }

 

    public override string Category

    {

      get

      {

        return this.basePropertyDescriptor.Category;

      }

    }

 

    public override Type ComponentType

    {

      get

      {

        return this.basePropertyDescriptor.ComponentType;

      }

    }

 

    public override TypeConverter Converter

    {

      get

      {

        return this.basePropertyDescriptor.Converter;

      }

    }

 

    public override string Description

    {

      get

      {

        return this.basePropertyDescriptor.Description;

      }

    }

 

    public override bool DesignTimeOnly

    {

      get

      {

        return this.basePropertyDescriptor.DesignTimeOnly;

      }

    }

 

    //This method is overridden to take notice of the FriendlyNameAttribute

    //if it has been applied to the property 

    public override string DisplayName

    {

      get

      {

        foreach(Attribute a in this.AttributeArray)

        {

          if(a is FriendlyNameAttribute)

          {

            return ((FriendlyNameAttribute)a).Name;

          }

        }

        return this.basePropertyDescriptor.DisplayName;

      }

    }

 

    public override bool Equals(object obj)

    {

      return this.basePropertyDescriptor.Equals (obj);

    }

 

    public override PropertyDescriptorCollection GetChildProperties(object instance, Attribute[] filter)

    {

      return this.basePropertyDescriptor.GetChildProperties (instance, filter);

    }

 

    public override object GetEditor(Type editorBaseType)

    {

      return this.basePropertyDescriptor.GetEditor (editorBaseType);

    }

 

    public override int GetHashCode()

    {

      return this.basePropertyDescriptor.GetHashCode ();

    }

 

    public override object GetValue(object component)

    {

      return this.basePropertyDescriptor.GetValue(component);

    }

 

    public override bool IsBrowsable

    {

      get

      {

        return this.basePropertyDescriptor.IsBrowsable;

      }

    }

 

    public override bool IsLocalizable

    {

      get

      {

        return this.basePropertyDescriptor.IsLocalizable;

      }

    }

 

    public override bool IsReadOnly

    {

      get

      {

        return this.basePropertyDescriptor.IsReadOnly;

      }

    }

 

    public override string Name

    {

      get

      {

        return this.basePropertyDescriptor.Name;

      }

    }

 

    public override Type PropertyType

    {

      get

      {

        return this.basePropertyDescriptor.PropertyType;

      }

    }

 

    public override void RemoveValueChanged(object component, EventHandler handler)

    {

      this.basePropertyDescriptor.RemoveValueChanged (component, handler);

    }

 

    public override void ResetValue(object component)

    {

      this.basePropertyDescriptor.ResetValue(component);      

    }

 

    public override void SetValue(object component, object value)

    {

      this.basePropertyDescriptor.SetValue(component, value);

    }

 

    public override bool ShouldSerializeValue(object component)

    {

      return this.basePropertyDescriptor.ShouldSerializeValue(component);

    }

 

    public override string ToString()

    {

      return this.basePropertyDescriptor.ToString ();

    }

  }

 

Use the Back button on your browser to return to the article

Copyright © Bob Powell 2003-2009. All rights reserved