471,330 Members | 1,724 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,330 software developers and data experts.

The property is not serialized!

Hi folks,
I've got a TypeConverter, say, GraphInfoTypeConverter, that is supposed to
convert String and/or InstanceDescriptor types into a given class named
GraphInfo. On the other hand, I\ve got a property named MyProp in
MyMainControlClass, 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
MyMainControlClass. Here's the GraphInfoTypeConverter class:

using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.ComponentModel.Design.Serialization;
using System.Collections;
using System.Reflection;
namespace GraphMonitor
{
public class GraphInfoTypeConverter : TypeConverter
{
String[] Delimiters = new String[] { "," };
public override bool CanConvertFrom(ITypeDescriptorContext context, Type
sourceType)
{
if (sourceType == typeof(String))
return true;
return base.CanConvertFrom(context, sourceType);
}
public override object ConvertFrom(ITypeDescriptorContext context,
System.Globalization.CultureInfo culture, object value)
{
if (value != null && value is String)
{
String[] Result = ((String)value).Split(Delimiters,
StringSplitOptions.RemoveEmptyEntries);
if (Result.Length != 1)
throw new Exception("invalid length");
return new GraphInfo(double.Parse(Result[0].Trim()));
}
return base.ConvertFrom(context, culture, value);
}
public override bool CanConvertTo(ITypeDescriptorContext context, Type
destinationType)
{
if (destinationType == typeof(String) ||
destinationType == typeof(InstanceDescriptor))
return true;
return base.CanConvertTo(context, destinationType);
}
public override object ConvertTo(ITypeDescriptorContext context,
System.Globalization.CultureInfo culture, object value, Type
destinationType)
{
if (value != null)
{
if (destinationType == typeof(String) && value is GraphInfo)
{
GraphInfo gi = (GraphInfo)value;
return gi.Value.ToString();
}
if (destinationType == typeof(InstanceDescriptor) && value is GraphInfo)
{
GraphInfo gi = (GraphInfo)value;
ConstructorInfo ctor = typeof(GraphInfo).GetConstructor(new Type[] {
typeof(Double) });
return new InstanceDescriptor(ctor, new object[] { gi.Value });
}
}
return base.ConvertTo(context, culture, value, destinationType);
}
public override bool GetPropertiesSupported(ITypeDescriptorContext context)
{
return true;
}
public override PropertyDescriptorCollection
GetProperties(ITypeDescriptorContext context, object value, Attribute[]
attributes)
{
if (value is GraphInfo)
return TypeDescriptor.GetProperties(typeof(GraphInfo), attributes);
return base.GetProperties(context, value, attributes);
}
public override bool GetCreateInstanceSupported(ITypeDescriptorContext
context)
{
return true;
}
public override object CreateInstance(ITypeDescriptorContext context,
IDictionary propertyValues)
{
return new GraphInfo((double)propertyValues["Value"]);
}
}
}
Any help would be highly appreciated,

TIA,
Mehdi
Jun 27 '08 #1
0 974

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Richard Collette | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.