SQL Server CLR聚合:序列化字典? [英] SQL Server CLR Aggregate: Serialize a Dictionary?

查看:84
本文介绍了SQL Server CLR聚合:序列化字典?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用C#编写自定义CLR聚合以在SQL Server 2008中运行。我想将我的大多数 SqlUserDefinedAggregate 实例的状态保存在字典中,所以我可以不要使用内置的序列化。

I'm writing a custom CLR Aggregate in C# to run in SQL Server 2008. I want to hold most of my SqlUserDefinedAggregate instances' states in Dictionaries, so I can't use the builtin serialization.

如何使用 Read() UserDefined 序列化c $ c>和 Write()方法?

How can I go about using UserDefined serialization with the Read() and Write() methods?

推荐答案

使用键以及 BinaryReader BinaryWriter 处理的类型的值,将每个Dictionary写入key0,value0中的BinaryWriter中。 keyN-1,值N-1顺序。在字典的 Count 之前添加此序列的前缀。在序列之后,编写一个常数以验证字典的结尾。我个人喜欢 0xDEADBEEF

Using keys and values of types that BinaryReader and BinaryWriter handle, Write each Dictionary out to the BinaryWriter in key0,value0...keyN-1,valueN-1 order. Prefix this sequence with Dictionary's Count. After the sequence, write a constant to verify end of dictionary. Personally I like 0xDEADBEEF.

对于反序列化,请执行相反的操作:将循环初始化为运行n次(n为流中的第一个整数),然后在您从键/值对中读取时将其添加到字典中。最后,检查您的常数。

For deserialization, do the reverse: Intialize a loop to run n times (n is the first integer in your stream), and add to Dictionary as you read in key/value pairs. At the end, check for your constant.

这篇关于SQL Server CLR聚合:序列化字典?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆