我想在页面的ViewState中保存我的自定义类对象,可是在运行时报下列错误:
类型“DynamicReport.AppClass.Report”(我的自定义类)必须标记为 Serializable 或者具有 ReferenceConverter 以外的 TypeConverter,才能被放置在视图状态中。我在我的自定义类中添加了[Serializable]特性,但还是报同样的错!是不是需要对我的类进行序列化??
如何对自定义类进行序列化啊!????
类型“DynamicReport.AppClass.Report”(我的自定义类)必须标记为 Serializable 或者具有 ReferenceConverter 以外的 TypeConverter,才能被放置在视图状态中。我在我的自定义类中添加了[Serializable]特性,但还是报同样的错!是不是需要对我的类进行序列化??
如何对自定义类进行序列化啊!????
解决方案 »
- 求助sql合并
- JS好象执行了,但没效果...
- 往access里面追加记录的问题。怎么这么简单的问题都问了3回了还没有正确的答案哪?
- 为什么我在连接oracle9i的时候总是说我缺少oci.dll?
- 关于如何在aspxC#中实现自动生成HTML页
- C# 请求远程HTML内容 出现乱码
- 复制一个已经存在的aspx页面,修改成为另外一个页面,然后新的页面出现很多稀奇古怪的问题
- 在 Entities 中怎么直接写查询语句
- 客户端与服务器端的问题?
- 在ASP.NET中能控制输入法吗?在.NET应用程序中有一INPUTLANGUAGE类,可以控制,在ASP.NET中能实现吗?
- 如何改变TreeView结点的CSS样式?
- 一个简单的网络访问设置问题!
http://msdn.microsoft.com/msdnmag/issues/03/02/CuttingEdge/
2,使对象继承ISerializable;
3,使现序列化构造函数;
4,实现Equals和GetHashCode.以下是代码示例:各函数功能可参考sdk
[Serializable]
public class OrderItem : Toworld.TradingMS.Core.BizObject, ISerializable
{
private int itemID;
private int orderID;
private int productID;
private Single quantity;
private Decimal price;
private string productNo;
private string productName;
// *************************************************
// CTOR
public OrderItem()
{
}
// *************************************************** // ***************************************************
// CTOR
protected OrderItem( SerializationInfo info, StreamingContext context )
{
itemID = info.GetInt32( "ItemID" );
orderID = info.GetInt32( "OrderID" );
productID = info.GetInt32( "ProductID" );
quantity = info.GetSingle( "Quantity" );
price = info.GetDecimal( "Price" );
productNo = info.GetString( "ProductNo" );
productName = info.GetString( "ProductName" );
}
// ***************************************************
// ***************************************************
// IMPLEMENT GetObjectData
public void GetObjectData( SerializationInfo info, StreamingContext context )
{
info.AddValue( "ItemID", itemID );
info.AddValue( "OrderID", orderID );
info.AddValue( "ProductID", productID );
info.AddValue( "Quantity", quantity );
info.AddValue( "Price", price );
info.AddValue( "ProductNo", productNo );
info.AddValue( "ProductName", productName );
info.AddValue( "State", (int)state );
}
// *****************************************************
// *****************************************************
// OVERRIDE Eqnuals
public override bool Equals( object o )
{
return (itemID == ((OrderItem)o).ItemID) &&
(productID == ((OrderItem)o).ProductID);
}
// ***************************************************** // *****************************************************
// OVERRIDE GetHashCode
public override int GetHashCode()
{
return itemID * 13 + productID * 23;
}
// ***************************************************** //.....
}
formatter.Serialize(Response.OutputStream,你的对象实例);
例如:[Serializable]
class Order
{
....
....
}
性能不是最优的,建议实现typeconverter