URGENT , designtime serialization

R

roger

Hi, i have a serious problem with designtime serialization
in one of my windows forms controls

the control exposes a collection of "Bands"

MyControl
{
public BandCollection Bands{ get ...}
}

what i want to do is to make my "band" objects persist to
the forms designer initialize code in the following way:


private void InitializeComponent()
{
.......

MyControl1.Bands.AddRange(new Band[] {
new Band(123,"abc",1.23,this.TextBox1),
new Band(888,"hhh",567,this.TextBox2),
new Band(123,"iii",888,null),
});

.....
}


whad do i need in order to do this?
i have tried the following ways:

1) implement ISerializable on the band , and add a
expandableobject converter ... this failed since some of
the parameters needed to create an instance wasnt
serializable

2) making the band inherit from component... this worked
fine , but added zillions of components to the form , i
dont want this..

3) just using a expandable object converter , this also
fails , it doesnt seem like it can persist references to
other designer memebrs such as "this.textbox1" (it was
always replaced with null)



so what do i need??
CodeDom serialization??
samples would also be very nice :)

//Roger
 
I

Iulian Ionescu

After many hours spent trying to have the collections
serialized correctly automatically I gave up. Everytime I
am confronted with this I create a custom
CodeDomSerializer and I do something similar to this:

if (myobject.someCollection.Count>0)
{
...use code dom to create the collection yourself.
}

I use the SerializeProperties method of the
CodeDomSerializer a lot which is very useful but you need
and also SerializeToExpression. Make sure you properly
define in the TypeConverter the constructor you want to
be used. Going this way I never had problems.

One thing to note though. If you want to create
additional settings like this:

MyControl1.Bands[0].SomeProperty = ...

I found out that it doesn't work. I had to create a
GetItem method that returns the same as the index:

MyControl1.Bands.GetItem[0].SomeProperty = ...
 
C

CoderGuy

I am having problems in this area in general too.
One example that helped me was from the below link:
(watch for link wrapping)

http://www.divil.co.uk/net/articles/designers/collectionco
ntrols.asp

I have gotten Content.Visiblity CODEDom
serialization "almost" working, except for one problem
where the instance of the collection that was serialized
somehow becomes dissasociated after I reload or run my
application. It works normally when I Add/Remove items as
far as Code-generation goes and what-not, until you
reload (which of course defeats the purpose :)

I have posted a longer explanation of my problem in this
same newsgroup (search for CodeDom Serialization), if
either of you guy's think you might have any ideas on it -
I would appreciate it.

As far as your problem goes with the CodeDOM generating
Add-Range, I am not sure.

I am still just trying to get the CODE-DOM serializer
working 100% on my end with a standard collection.Add
syntax. Like...

ParentControl.ChildCollection.Add("SomeChild")

Like I said, the CODEDom generation works, but then when
I reload my APP. - even though the code is there - it
neither appears in my form or is inside the actual
collection it say's that it is. Strange problem.

Hopefully the example from the HTTP link I pasted above
might be of some use to someone.

Thanks,

Coderguy
 

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

Top