views:

140

answers:

0

I'm using a custom TypeDescriptionProvider and a custom TypeDescriptor to allow users to attribute objects with their own custom properties. For example I have two classes which are sometimes displayed in a PropertyGrid SiteRegion, and FootPrintBuilding. Each is attributed with my custom TypeDescriptionProvider.

[TypeDescriptionProvider(typeof(InfCustomTypeProvider<SiteRegion>))]
public class SiteRegion : RhNode, ISiteRegion
{

//contents of SiteRegion  class           
}

[TypeDescriptionProvider(typeof(InfCustomTypeProvider<FootprintBuilding>))]
public class FootprintBuilding : RhNodeBuilding, IBuilding
{
//contents of FootprintBuilding class       
}

This custom type provider adds on custom properties based on the type of objects being displayed. I swear this was working before, but now it's not. When I display a FootPrintBuilding in the property grid it works fine. It both displays concrete and custom properties. And more importantly if I set a break point in the constructor for InfCustomTypeProvider Visual Studio will stop at that breakpoint. However, if I try to display a SiteRegion in a property grid not only do I not see any custom properties, but it doesn't even hit the breakpoint I have set in the InfCustomTypeProvider constructor. It's acting like the attribute isn't even there.

My InfCustomTypeProvider class is below. Does anyone have any idea why one attribute is recognized and not the other? Also does anyone have any ideas of something else I can try to possibly troubleshoot this?

class InfCustomTypeProvider<T> : TypeDescriptionProvider
{
    private static TypeDescriptionProvider defaultTypeProvider = TypeDescriptor.GetProvider(typeof(T));

    public InfCustomTypeProvider()
        : base(defaultTypeProvider)
    {

    }

    public override ICustomTypeDescriptor GetTypeDescriptor(Type objectType, object instance)
    {
        ICustomTypeDescriptor defaultDescriptor = base.GetTypeDescriptor(objectType, instance);
        return new InfCustomTypeDescriptor(defaultDescriptor,objectType);
    }
}

Update 2009-12-17

It wasn't working last night, came in this morning and tried it again and it worked once, but I tried it a second time and it stopped working. I have no idea what was different, I hadn't changed the code at all? Whenever the code actually calls the constructor of my custom TypeDescriptor my custom properties show up fine, so the issue seems to be it even recognizing the type has a custom type descriptor. I've also tried calling TypeDescriptor.Refresh(typeof(SiteRegion)), and manually getting all the properties for the type using TypeDescriptor.GetProperties(). Neither evoke my custom TypeDescriptor, or return my custom properties?