Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / Design Time / April 2005

Tip: Looking for answers? Try searching our database.

Code serialization for a collection property

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Bernd S - 05 Apr 2005 12:12 GMT
Hi,

how is it possible to serialize a collection into code similar as the
ControlCollection serialization? The problem what I see is that
CollectionCodeComSerializer is an internal class which cannot be overrided.

Thanks,
Bernd
joeycalisay - 06 Apr 2005 04:55 GMT
Have you tried adding DesignerSerializationVisibility.Content attribute to
the Collection property?

Signature

Joey Calisay
http://spaces.msn.com/members/joeycalisay/

> Hi,
>
[quoted text clipped - 4 lines]
> Thanks,
> Bernd
Bernd S - 06 Apr 2005 09:16 GMT
Yes, but as far as I know I additionally have to use a
DesignerSerializerAttribute for the collection class to specify an
appropriate CodeDomSerializer.
"System.ComponentModel.Design.Serialization.CollectionCodeDomSerializer"
would be appropriate, but it is an internal class. So I wonder whether I
have to write my own CollectionCodeDomSerializer.

> Have you tried adding DesignerSerializationVisibility.Content attribute to
> the Collection property?
[quoted text clipped - 8 lines]
> > Thanks,
> > Bernd
joeycalisay - 07 Apr 2005 01:30 GMT
CollectioCodeDomSerializer is used by default of all Collection type
properties by VS.  In a normal scenario, you don't have to extend it, just
have a Content attribute on the collection property and it will be
serialized, sometimes you might need a TypeConverter, I myself in my
experience did not need to extend the said class.  Do you really want to
extend it and why?

Signature

Joey Calisay
http://spaces.msn.com/members/joeycalisay/

> Yes, but as far as I know I additionally have to use a
> DesignerSerializerAttribute for the collection class to specify an
[quoted text clipped - 15 lines]
> > > Thanks,
> > > Bernd
Bernd S - 07 Apr 2005 10:00 GMT
Ok, I do not need to override the class CollectionCodeDomSerializer. There
was another problem that
[DesignerSerializer( typeof( CollectionCodeDomSerializer), typeof(
CodeDomSerializer ) )]

is not possible because CollectionCodeDomSerializer is an internal class but
now I use

[DesignerSerializer(
"System.ComponentModel.Design.Serialization.CollectionCodeDomSerializer",
typeof( CodeDomSerializer ) )]

and so the CollectionCodeDomSerializer is used for my collection.

Now code serialization works fine, i.e. the CollectionCodeDomSerializer
generates a line like

this.MyCollectionProp.Add(this.MyItemComponent);

but the deserialization seems not to work after closing and then re-opening
the document: Only an empty collection is created, i.e. the collection
editor shows no elements.
Do you have a clue what the reason could be?

> CollectioCodeDomSerializer is used by default of all Collection type
> properties by VS.  In a normal scenario, you don't have to extend it, just
[quoted text clipped - 23 lines]
> > > > Thanks,
> > > > Bernd
joeycalisay - 07 Apr 2005 10:35 GMT
Actually the DesignerSerializer is not needed, VS defaults to use it for
collection types.  Can you paste code for your custom collection class
MyCollectionProp

Signature

Joey Calisay
http://spaces.msn.com/members/joeycalisay/

> Ok, I do not need to override the class CollectionCodeDomSerializer. There
> was another problem that
[quoted text clipped - 30 lines]
> > > DesignerSerializerAttribute for the collection class to specify an
> > > appropriate CodeDomSerializer.

"System.ComponentModel.Design.Serialization.CollectionCodeDomSerializer"
> > > would be appropriate, but it is an internal class. So I wonder whether I
> > > have to write my own CollectionCodeDomSerializer.
[quoted text clipped - 14 lines]
> > > > > Thanks,
> > > > > Bernd
Bernd S - 08 Apr 2005 08:49 GMT
The collection property is implemented as

[Category( SmfAttrTypeText.ISmfPageControl.AllVisConfigPageSpecs.Category )]
[Description(
SmfAttrTypeText.ISmfPageControl.AllVisConfigPageSpecs.Description )]
[DesignerSerializationVisibility( DesignerSerializationVisibility.Content )]
public PageSpecCollection AllVisConfigurablePageSpecs
{
  get
  {
     return this.Runtime.AllVisConfigurablePageSpecs;
  }

 // leaving out this set accessor causes the code deserialization to
work!!!
  set
  {
     this.Runtime.AllVisConfigurablePageSpecs = value;
  }
}

and the custom collection class as

public class PageSpecCollection : CollectionBase
{
public PageSpecCollection()
{
}
public PageSpecCollection ( PageSpecCollection value)
{
this.AddRange(value);
}
public PageSpecCollection( PageSpec[] value)
{
this.AddRange(value);
}
public int Add(PageSpec value)
{
return this.List.Add(value);
}
public void AddRange(PageSpec[] value)
{
if (value == null)
{
throw new ArgumentNullException("value");
}
for (int index = 0; index < value.Length; index++)
{
this.Add(value[index]);
}
}
public void AddRange(PageSpecCollection value)
{
if (value == null)
{
throw new ArgumentNullException("value");
}
int cnt = value.Count;
for (int index = 0; index < cnt; index++)
{
this.Add(value[index]);
}
}
public bool Contains(PageSpec value)
{
return this.List.Contains(value);
}
public void CopyTo(PageSpec[] array, int index)
{
this.List.CopyTo(array, index);
}
public int IndexOf(PageSpec value)
{
return this.List.IndexOf(value);
}
public void Insert(int index, PageSpec value)
{
this.List.Insert(index, value);
}
public void Remove(PageSpec value)
{
this.List.Remove(value);
}
public PageSpec this[int index]
{
get
{
return (PageSpec) this.List[index];
}
set
{
this.List[index] = value;
}
}

The strange thing is that meanwhile I found out that leaving out the set
accessor of the collection property causes the code deserialization to work.
But I cannot imagine why.

> Actually the DesignerSerializer is not needed, VS defaults to use it for
> collection types.  Can you paste code for your custom collection class
[quoted text clipped - 10 lines]
> >
> > [DesignerSerializer(

"System.ComponentModel.Design.Serialization.CollectionCodeDomSerializer",
> > typeof( CodeDomSerializer ) )]
> >
[quoted text clipped - 43 lines]
> > > > > > Thanks,
> > > > > > Bernd
Mick Doherty - 08 Apr 2005 10:54 GMT
A Collection property is ReadOnly because you want to modify it's items and
not exchange the collection object itself.

Signature

Mick Doherty
http://dotnetrix.co.uk/nothing.html

> The collection property is implemented as
>
[quoted text clipped - 97 lines]
> work.
> But I cannot imagine why.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.