Using a Custom Design Serializer

  • Thread starter Thread starter Myron Marston
  • Start date Start date
M

Myron Marston

Has anyone gotten a custom DesignSerializer to work with the compact
framework? I've got some custom controls that I'd like to use a custom
serializer for, and I keep getting an Invalid Cast Exception deep in
the bowels of the Visual Studio code.

Thanks,
Myron
 
Can you describe more of what you are doing? You are trying to use
designer code like PropertyGrid and ComponentModel.Editor stuff on a
device running CF stuff? DesignerSerializerAttribute, etc is not
supported by the CF.

Or is this for use in Visual Studio?
 
Yes, this is for use in VS. I know that the CF doesn't support
DesignerSerializerAttribute (it doesn't really support any design time
stuff), but my control library has a design-time version and a run time
version, and I want DesignerSerialization support during design time.
Specifically, I am trying to change the way a Label's text property
serializes, so that it makes a call to a method I have called
GetTranslatableText().

I followed the steps outlined in the second post at:

http://groups-beta.google.com/group...deDomSerializer&rnum=1&hl=en#b5714b54d3274b07

However, I am getting the exact same exception and stack trace as in
the first post.
 
Myron,
I've done a decent amount of designer stuff, if you have a small
example I could run I wouldn't mind looking at it later tonight.
 
At the moment I am just trying to get a DesignerSerializer to work with
a CF Custom Control. I don't really care what it does, so long as it
works.

The example from the other thread is a pretty good stripped-down
example, so I've been trying to get that to work. Here's the source
code for it:

using System;
using System.Design;
using System.ComponentModel.Design.Serialization;
using System.ComponentModel.Design;
using System.ComponentModel;
using System.Windows.Forms;

[assembly:System.CF.Design.RuntimeAssembly("")]

namespace test_comp
{
[
DesignerSerializer(typeof(MyComponentSerializer),typeof(CodeDomSerializer)),

ToolboxItemFilter("System.CF.Windows.Forms",
ToolboxItemFilterType.Custom),
ToolboxItemFilter("NETCF", ToolboxItemFilterType.Require)
]
public class MyComponent : Component
{
private string myString;
public string MyString
{
get
{
return myString;
}
set
{
myString = value;
}
}
}

internal class MyComponentSerializer: CodeDomSerializer
{
public override object Deserialize(IDesignerSerializationManager
manager, object codeObject)
{
CodeDomSerializer baseSerializer =
(CodeDomSerializer)manager.GetSerializer(typeof(MyComponentSerializer).BaseType,
typeof(CodeDomSerializer));
return baseSerializer.Deserialize(manager, codeObject);
}
public override object Serialize(IDesignerSerializationManager
manager, object value)
{
MessageBox.Show("Hello There!");

CodeDomSerializer baseSerializer =
(CodeDomSerializer)manager.GetSerializer(typeof(MyComponentSerializer).BaseType,
typeof(CodeDomSerializer));
return baseSerializer.Serialize(manager, value);
}
}
}

Thanks for being willing to take a look at this!
 
Back
Top