Type Descriptors, Converters and designer serialization

  • Thread starter Chris B via .NET 247
  • Start date
C

Chris B via .NET 247

(Type your message here)

Hi ive built a custom menubar control that uses a strongly typedHashtable to store the colours needed to paint the control, andi have made this collection available to the proprty grid invs.net by implementing ICustomTypeDescriptor on the collectionand also by creating a class that inherits PropertyDescriptor.

My problem is that i have set thedesignerserializationvisibilityattribute to content, but when itserialises the settings it does it incorrectly

i.e

these are the serialized settings created by vs.net, whichappears to be treating the Hashtable members like they wereactual properties.



visual basic code:

Me.m1.Colours.back = System.Drawing.SystemColors.Control
Me.m1.Colours.clientback = System.Drawing.SystemColors.Control
Me.m1.Colours.disabledback = System.Drawing.Color.LightBlue
Me.m1.Colours.disabledfore =System.Drawing.Color.DarkGray--------------------------------------------------------------------------------

Now the problem with these is that instead of a fullstop inbetween Colours and the Hashtable item there should be either a( for vb or a [ for c# and then the item name in quotes

VB

Me.m1.Colours("DisabledFore") = Color

C#

this.m1.Colours["DisabledFore"] = Color;

Ive experimented with type converters but they just dont seem towork.

heres the code for the type converter



public class ColourCollectionConverter :ExpandableObjectConverter
{
public ColourCollectionConverter()
{
}

public override bool
CanConvertTo( ITypeDescriptorContext context, TypedestinationType )
{
if ( destinationType == typeof( InstanceDescriptor ))
{

return true;
}
else return base.CanConvertTo( context, destinationType );
}

public override boolGetPropertiesSupported(ITypeDescriptorContext context)
{
return true;
}

public override object
ConvertTo( ITypeDescriptorContext context,
System.Globalization.CultureInfo culture, object value, Type
destinationType )
{
int i=0;
if ( destinationType == typeof( InstanceDescriptor ))
{
cbColourCollection points = (cbColourCollection) value;
Color[] values = new Color[ points.Count ];

foreach(Color c in points)
{
values = (Color)c;
i++;
}

return new InstanceDescriptor(typeof(cbColourCollection).GetConstructor( new Type[] {values.GetType() }),new object[] {values },
true );
}
else
return base.ConvertTo (context, culture,value,destinationType);
}
}



Does anyone have any ideas how to get vs to output thiscorrectly?


thanks in advance


From: Chris B
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,066
Latest member
VytoKetoReviews

Latest Threads

Top