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.
"joeycalisay" <hcalisay@_spamkiller_codex-systems.com> schrieb im
Newsbeitrag news:%23qvyoU1OFHA.2520@tk2msftngp13.phx.gbl...
[quoted text, click to view] > Actually the DesignerSerializer is not needed, VS defaults to use it for
> collection types. Can you paste code for your custom collection class
> MyCollectionProp
>
> --
> Joey Calisay
>
http://spaces.msn.com/members/joeycalisay/ >
>
> "Bernd S" <B.Sonderkoetter@nospam.smf.de> wrote in message
> news:%23%23aLDB1OFHA.2144@TK2MSFTNGP09.phx.gbl...
> > 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?
> >
> >
> >
> > "joeycalisay" <hcalisay@_spamkiller_codex-systems.com> schrieb im
> > Newsbeitrag news:%231X2KkwOFHA.3408@TK2MSFTNGP14.phx.gbl...
> > > 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?
> > >
> > > --
> > > Joey Calisay
> > >
http://spaces.msn.com/members/joeycalisay/ > > >
> > >
> > > "Bernd S" <B.Sonderkoetter@nospam.smf.de> wrote in message
> > > news:ueCz9DoOFHA.508@TK2MSFTNGP12.phx.gbl...
> > > > 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.
> > > >
> > > > "joeycalisay" <hcalisay@_spamkiller_codex-systems.com> schrieb im
> > > > Newsbeitrag news:uJ8qIylOFHA.1172@TK2MSFTNGP12.phx.gbl...
> > > > > Have you tried adding DesignerSerializationVisibility.Content
> > attribute
> > > to
> > > > > the Collection property?
> > > > >
> > > > > --
> > > > > Joey Calisay
> > > > >
http://spaces.msn.com/members/joeycalisay/ > > > > >
> > > > >
> > > > > "Bernd S" <B.Sonderkoetter@nospam.smf.de> wrote in message
> > > > > news:%23n2yeBdOFHA.2136@TK2MSFTNGP14.phx.gbl...
> > > > > > 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
> > > > > >
> > > > > >
> > > > > >
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >
> >
> >
>
>