Dynamic usage of properties

Oct 1, 2010 at 9:23 AM



Firstly, I just can follow up the other posts, this is a great piece of code.


But I have a problem, I can't find a solution yet - hope you can help me:

I have an object containing a value as string and a dataType as Enum. The datyType can be bool, int and string. Depending on the dataType, the editing function of the value should be for bool, int or string.


So, that's the problem. Several solutions came in my mind, but no one works:

Idea 1: I will create three properties (ValueString, ValueBool and ValueInt), hiding the unneeded with [Browsable(false)]. This is not working, because I can't change the browsable attribute at runtime (or better, I didn't found a way)


Idea 2: Creating the three properties from idea 1, but use an other hiding mechanism: In your example code, exactly within the FeaturesDemo, you use the property 'declared only' to hide all, but the two properties in the subclass. But I didn't found out, how you (or general) set the 'declared' property. And can this be done at runtime?


It would be great if you have any ideas for my problem and thanks in advance,


Oct 4, 2010 at 10:01 PM

Maybe this can be solved with a custom TypeDescriptor/TypeDescriptionProvider? Where you modify the GetProperties list depending on the dataType enum... I am not sure, have not tried.

I am implementing the IsVisible property on the PropertyViewModel now - then it should be possible to change the visibility of the ValueString/ValueBool/ValueInt at runtime.

The DeclaredOnly just hides the inherited properties, I don't think that can be used in your case.

Oct 5, 2010 at 7:07 AM

Hi objo!

Thanks for your response. When I found some time, I will try the TypeDescriptor/TypeDescriptorProvider.

We will see what comes first, my typeDescriptor or your IsVisible property - which sounds a nice extension to your project.