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?
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.