The property is not serialized!

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mehrdad

    The property is not serialized!

    Hi folks,
    I've got a TypeConverter, say, GraphInfoTypeCo nverter, that is supposed to
    convert String and/or InstanceDescrip tor types into a given class named
    GraphInfo. On the other hand, I\ve got a property named MyProp in
    MyMainControlCl ass, that's of type GraphInfo.
    Whenever the GraphInfo's value is changed, the new values won't serialize
    into "Form1.Designer .cs" where Form1 is the class hosting the
    MyMainControlCl ass. Here's the GraphInfoTypeCo nverter class:

    using System;
    using System.Collecti ons.Generic;
    using System.Text;
    using System.Componen tModel;
    using System.Componen tModel.Design.S erialization;
    using System.Collecti ons;
    using System.Reflecti on;
    namespace GraphMonitor
    {
    public class GraphInfoTypeCo nverter : TypeConverter
    {
    String[] Delimiters = new String[] { "," };
    public override bool CanConvertFrom( ITypeDescriptor Context context, Type
    sourceType)
    {
    if (sourceType == typeof(String))
    return true;
    return base.CanConvert From(context, sourceType);
    }
    public override object ConvertFrom(ITy peDescriptorCon text context,
    System.Globaliz ation.CultureIn fo culture, object value)
    {
    if (value != null && value is String)
    {
    String[] Result = ((String)value) .Split(Delimite rs,
    StringSplitOpti ons.RemoveEmpty Entries);
    if (Result.Length != 1)
    throw new Exception("inva lid length");
    return new GraphInfo(doubl e.Parse(Result[0].Trim()));
    }
    return base.ConvertFro m(context, culture, value);
    }
    public override bool CanConvertTo(IT ypeDescriptorCo ntext context, Type
    destinationType )
    {
    if (destinationTyp e == typeof(String) ||
    destinationType == typeof(Instance Descriptor))
    return true;
    return base.CanConvert To(context, destinationType );
    }
    public override object ConvertTo(IType DescriptorConte xt context,
    System.Globaliz ation.CultureIn fo culture, object value, Type
    destinationType )
    {
    if (value != null)
    {
    if (destinationTyp e == typeof(String) && value is GraphInfo)
    {
    GraphInfo gi = (GraphInfo)valu e;
    return gi.Value.ToStri ng();
    }
    if (destinationTyp e == typeof(Instance Descriptor) && value is GraphInfo)
    {
    GraphInfo gi = (GraphInfo)valu e;
    ConstructorInfo ctor = typeof(GraphInf o).GetConstruct or(new Type[] {
    typeof(Double) });
    return new InstanceDescrip tor(ctor, new object[] { gi.Value });
    }
    }
    return base.ConvertTo( context, culture, value, destinationType );
    }
    public override bool GetPropertiesSu pported(ITypeDe scriptorContext context)
    {
    return true;
    }
    public override PropertyDescrip torCollection
    GetProperties(I TypeDescriptorC ontext context, object value, Attribute[]
    attributes)
    {
    if (value is GraphInfo)
    return TypeDescriptor. GetProperties(t ypeof(GraphInfo ), attributes);
    return base.GetPropert ies(context, value, attributes);
    }
    public override bool GetCreateInstan ceSupported(ITy peDescriptorCon text
    context)
    {
    return true;
    }
    public override object CreateInstance( ITypeDescriptor Context context,
    IDictionary propertyValues)
    {
    return new GraphInfo((doub le)propertyValu es["Value"]);
    }
    }
    }


    Any help would be highly appreciated,

    TIA,
    Mehdi


Working...