由于序列化的时候错误难以详细报出.所以这里收集一下大家认为对对象进行序列化的时候的注意事项.比如我先说我知道的几个1 .不要用接口定义属性类型
2 .属性类型必须都可序列化希望大家补充修正。
2 .属性类型必须都可序列化希望大家补充修正。
解决方案 »
- C# SQL数据库里面存的是图片的路径,怎么在datagridview里面把路径显示成图片
- 操作ACCESS表的怪事情
- winform 打包的问题
- C# 资源国际化的问题?
- RemotingObject对象中需要使用配置文件变量时怎么处理?
- 由于控件数量很多,窗体重绘时控件闪烁如何解决
- 帮忙看看
- 如何在机器上安装 Visual Studio .NET 2003 都重装3回系统了。
- 请大神进来教教怎么获取文件夹中的最新更新的文件
- 如何为DATAGIRD添加SCROLLBAR?
- 当SQLSERVER使用windows身份验证时,使用SQLDMO连接数据库却连不上,为何
- 如何制作类似Widge的程序?
using System.Collections.Generic;
using System.Text;
using System.Data;namespace Luna.Base
{
[Serializable]
public abstract class AbstractComponent : ILunaComponent
{
[NonSerialized]
private LunaPropertyCollection propertyCollection;
private List<AbstractComponent> children;
private ComponentState state; public AbstractComponent()
{
propertyCollection = new LunaPropertyCollection(null);
state = ComponentState.Unchanged;
}
#region ILunaComponent 成员 public string ID
{
get
{
return GetProoertyValue("ID");
//if (propertyCollection["ID"] == null)
// return null;
//return propertyCollection["ID"].ToString();
}
set { SetProoertyValue("ID", value); }
}
public string Code
{
get
{
return GetProoertyValue("Name");
//if (propertyCollection["Code"] == null)
// return null;
//return propertyCollection["Code"].Value.ToString();
}
set
{
SetProoertyValue("Code", value);
}
} public string Name
{
get
{
return GetProoertyValue("Name");
//if (propertyCollection["Name"] == null)
// return null;
//return propertyCollection["Name"].Value.ToString();
}
set
{
SetProoertyValue("Name", value);
}
} public virtual string Table
{
get
{
return GetProoertyValue("LUNAOBJECT");
//if (propertyCollection["LUNAOBJECT"] == null)
// return null;
//return Properties["LUNAOBJECT"].Value;
}
} public string Description
{
get
{
return GetProoertyValue("Description");
//return propertyCollection["Description"].Value.ToString();
}
set
{
SetProoertyValue("Description", value);
}
} public string ComponentClass
{
get
{
return GetProoertyValue("ComponentClass");
//if (propertyCollection["ComponentClass"] == null)
// return null;
//return propertyCollection["ComponentClass"].Value.ToString();
}
} public DateTime CreateTime
{
get
{
if (propertyCollection["CreateTime"] == null || propertyCollection["CreateTime"].ToString().Trim() == "")
return DateTime.MinValue;
return ConvertUtil.GetDateTime(propertyCollection["CreateTime"].Value);
}
set
{
SetProoertyValue("CreateTime", ConvertUtil.GetString(value));
}
} public DateTime UpdateTime
{
get
{
if (propertyCollection["UpdateTime"] == null || propertyCollection["UpdateTime"].ToString().Trim() == "")
return DateTime.MinValue;
return ConvertUtil.GetDateTime(propertyCollection["UpdateTime"].Value);
}
set
{
SetProoertyValue("UpdateTime", ConvertUtil.GetString(value));
}
} public LunaPropertyCollection Properties
{
get { return propertyCollection; }
} protected void SetProoertyValue(string key,string value)
{
if (propertyCollection[key] == null)
{
this.propertyCollection.Add(key, value);
}
propertyCollection[key].Value = value;
} protected string GetProoertyValue(string key)
{
if (propertyCollection[key] == null)
{
return null;
}
else
{
return propertyCollection[key].Value;
}
} /// <summary>
/// 子集合
/// </summary>
public List<AbstractComponent> Children
{
get
{
if (children == null)
children = new List<AbstractComponent>();
return children;
}
set
{
children = value;
}
} public ComponentState State
{
get
{
return state;
}
set
{
state = value;
}
} #endregion
}
}当这个类的子类的对象实例被序列化时会提示xml声称错误。(只有在obj.Children.Count>0的时候会报错)请问为什么?