下面是自定义的两个类,第二个类是第一个类的集合类//自定义的StringItem类
public class StringItem:WebControl
{
}
//StringItem的集合类
public class StringItems : CollectionBase , IStateManager
{
public StringItems() : base()
{
}
public StringItem this[int index]
{
get
{
return (StringItem)base.List[index];
}
set
{
List[index] = value;
}
}
public void Add(StringItem aItem)
{
this.List.Add(aItem);
} public void Remove(int index)
{
if( index > 0 && index < base.Count - 1 )
{
base.RemoveAt( index );
}
}
}在webpart中这样序列化:[Browsable(true),
Category("自定义"),
DefaultValue(null),
WebPartStorage(Storage.Personal),
FriendlyName("动态菜单项"),
Description("动态菜单项"),
XmlElement(Type=typeof(WebControl)),   //<--------------序列处理1
XmlElement(Type=typeof(StringItem))    //<--------------序列处理2
]
public StringItems Strings
{           
get
{
if(_Strings == null)
_Strings = new StringItems();
return _Strings;
}          }可是在运行的时候还是提示:
Windows SharePoint Services 无法对该 Web 部件进行反序列化。请检查该属性的格式然后再试
(注:webpart的本质就是自定义控件,现在的问题是无法进行xml序列化,跟webpart无关)
到底该怎么序列化才可以阿。
请高手指教

解决方案 »

  1.   

    [ISerializable]public class StringItems : CollectionBase , IStateManager
    {
    .........
    }加上ISerializable 看看
      

  2.   

    帮,不知楼有没有解决?---------------
    欢迊来到麦高网-私活兼职首选平台 www.mgao.net
      

  3.   

    加上  XmlInclude 标记试试StringItem 本身需要能支持 Xml序列化如下[XmlInclude(typeof(StringItem))]
    public class StringItems : CollectionBase , IStateManager
    .....
      

  4.   

    想让控件序列化,不是+个attribute就可以的阿,需要遍历控件的所有子项