请问DATAROW如何支持序列化

cxx1997 2006-05-31 04:22:11
经过GOOGLE,发现目前.NET 2.0中DATASET 和DATATABLE支持序列化
但DATAROW还不支持

由于我们类库中大量使用了DATAROW作为参数和返回值
现在我们希望用最小的代价把这些类库通过REMOTING RemotingConfiguration.RegisterWellKnownServiceType发布出去

目前遇到一个很麻烦的问题就是DATAROW不支持序列化

如果我们将DATAROW都换成DATATABLE,那么目前代码改动很大
如果我们自己重新做一个类封装DATAROW并实现序列化,也觉得代价过高

请问有没有更好的方法?

谢谢

示例
目前类库
public class TBusiness:MarshalByRefObject
{
public TBusiness()
{
}

public DataRow SetLoginUser(DataRow aLoginUser)
{

}
}

发布代码
System.Type objtype1=typeof(nsCMSBusiness.TBusiness);
RemotingConfiguration.RegisterWellKnownServiceType(objtype1, aServerName, WellKnownObjectMode.SingleCall);

...全文
685 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
cxx1997 2006-06-20
  • 打赏
  • 举报
回复
tiaoci(我挑刺,我快乐)

你说的固然有道理,但我哪个SetLoginUser只是举例而已,有很多这样的方法的
tiaoci 2006-06-20
  • 打赏
  • 举报
回复
知错就改才是好孩子
tiaoci 2006-06-14
  • 打赏
  • 举报
回复
就是说像这种 SetLoginUser(DataRow user)

这种小方法是不应当出现在服务接口的
ytzz 2006-06-14
  • 打赏
  • 举报
回复
把DataRow加载到DataTable中来序列化.
tiaoci 2006-06-14
  • 打赏
  • 举报
回复
把这样一个 TBusiness:MarshalByRefObject

当作一个service,本身就已经错了,

我觉得应当再封装一层,这样就不用传递DataRow了

比方你原来写法(假设)

userRow = TOther.GetUserFromSession(sessionId);
TBusiness.SetLoginUser(userRow)
TBusiness.DoSomethingSpecial(...);

把这个整体做成一个Service

TService.DoSomethingSepcial(sessionId);

这样不就不用传递DataRow了吗?
zlkingdom 2006-06-14
  • 打赏
  • 举报
回复
如果要重构的话是不是要自己封装一个比较好呢
qpl007 2006-06-14
  • 打赏
  • 举报
回复
把DataRow加载到DataTable中来序列化,简单可行。
yumanqing 2006-06-14
  • 打赏
  • 举报
回复
支持搂主,顶了
cxx1997 2006-05-31
  • 打赏
  • 举报
回复
liujiwe79(独孤求胜) :
谢谢你提供的代码,但我关心的不是实现序列化和反序列化,而是如何在现有的系统中进行重构
Yuna_2z 2006-05-31
  • 打赏
  • 举报
回复
顶了
liujiwe79 2006-05-31
  • 打赏
  • 举报
回复
序列化其实也就是把对象生成xml文件流,你完全可以手工生成xml,同样读取xml反序列化出来,一样的道理,至于如何写代码要看你的实际需求了
#region 序列化方法

/// <summary>
/// 序列化该类的方法
/// </summary>
/// <param name="document">传递的文档</param>
/// <returns>该类的节点</returns>
public System.Xml.XmlNode Serialize(System.Xml.XmlDocument document)
{
XmlElement gridElement = document.CreateElement("GridPanel");

#region 序列化选区

if (this.TitleArea != null)
{
gridElement.AppendChild(this.TitleArea.Serialize(document, "TitleArea"));
gridElement.SetAttribute("TitleArea", "NotNull");
}
else
{
gridElement.SetAttribute("TitleArea", "Null");
}
if (this.DataArea != null)
{
gridElement.AppendChild(this.DataArea.Serialize(document, "DataArea"));
gridElement.SetAttribute("DataArea", "NotNull");
}
else
{
gridElement.SetAttribute("DataArea", "Null");
}

if (this.BottomArea != null)
{
gridElement.AppendChild(this.BottomArea.Serialize(document, "BottomArea"));
gridElement.SetAttribute("BottomArea", "NotNull");
}
else
{
gridElement.SetAttribute("BottomArea", "Null");
}

#endregion

//序列化单元格
for (int row = 0; row < this.Cells.GetLength(0); row++)
{
for (int col = 0; col < this.Cells.GetLength(1); col++)
{
Cell cell = this.cells[row, col];
if (cell != null)
{
gridElement.AppendChild(cell.Serialize(document));
}
}
}
gridElement.SetAttribute("Row", this.Cells.GetLength(0).ToString());
gridElement.SetAttribute("Column",this.cells.GetLength(1).ToString());
gridElement.SetAttribute("IsAutoDataSource", this.IsAutoDataSource.ToString());
return gridElement;
}
/// <summary>
/// 反序列化该类的方法
/// </summary>
/// <param name="node">传递的参数节点</param>
public void DeSerialize(System.Xml.XmlElement node)
{
int rowCount = Int32.Parse(node.GetAttribute("Row"));
int colCount = Int32.Parse(node.GetAttribute("Column"));
if (node.GetAttribute("IsAutoDataSource").Trim() !="")
{
this.IsAutoDataSource = bool.Parse(node.GetAttribute("IsAutoDataSource"));
}

#region 反序列化选区

string flag = node.GetAttribute("TitleArea");
if (flag == "Null")
{
this.TitleArea = null;
}
else
{
if (node.SelectSingleNode("TitleArea") != null)
{
XmlElement ele = node.SelectSingleNode("TitleArea") as XmlElement;
//标题区
if (this.TitleArea == null)
{
this.TitleArea = new SelectionArea(this);
}
this.TitleArea.DeSerialize(ele);
}
}
//数据区
flag = node.GetAttribute("DataArea");
if (flag == "Null")
{
this.DataArea = null;
}
else
{
if (node.SelectSingleNode("DataArea") != null)
{
XmlElement ele = node.SelectSingleNode("DataArea") as XmlElement;
//数据区
if (this.DataArea == null)
{
this.DataArea = new SelectionArea(this);
}
this.DataArea.DeSerialize(ele);
}
}
//表尾区
flag = node.GetAttribute("BottomArea");
if (flag == "Null")
{
this.BottomArea = null;
}
else
{
if (node.SelectSingleNode("BottomArea") != null)
{
//表尾区
XmlElement ele = node.SelectSingleNode("BottomArea") as XmlElement;
if (this.BottomArea == null)
{
this.BottomArea = new SelectionArea(this);
}
this.BottomArea.DeSerialize(ele);
}
}

#endregion

this.cells = new Cell[rowCount,colCount];
foreach (XmlElement element in node.ChildNodes)
{
//反序列化单元格
//Cell textCell = null;
if (element.Name.Substring(element.Name.Length - 4) != "Area")
{
Cell textCell = this.CellFactory(element.Name);
textCell.DeSerialize(element);
int row = textCell.Row;
int col = textCell.Column;
cells[row, col] = textCell;
}
}

}
#endregion
zhoujijunnt 2006-05-31
  • 打赏
  • 举报
回复
学习!顶!
cxx1997 2006-05-31
  • 打赏
  • 举报
回复
我打算在不改动类库的情况在,给类库加一个外壳
当收到外部请求时,调用内部类库,并将其中DATAROW数据类型进行转换

这个方面大家觉得怎么样?
Eddie005 2006-05-31
  • 打赏
  • 举报
回复
没有其他办法
Knight94 2006-05-31
  • 打赏
  • 举报
回复
你把DataRow加载到DataTable中来进行传输,可能是最简便的转换操作。

110,535

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧