SQL Server CLR 聚合:序列化字典?
我正在用 C# 编写一个自定义 CLR 聚合,以在 SQL Server 2008 中运行。我想在字典中保存大部分 SqlUserDefinedAggregate
实例的状态,因此我无法使用内置序列化。
如何通过 Read()
和 Write()
方法使用 UserDefined
序列化?
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.
How can I go about using UserDefined
serialization with the Read()
and Write()
methods?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
BinaryReader
和BinaryWriter
处理的类型的键和值,按 key0、value0...keyN-1、valueN-1 的顺序将每个字典写入 BinaryWriter。在此序列前添加字典的Count
前缀。在序列之后,写入一个常量来验证字典的结尾。我个人喜欢0xDEADBEEF
。对于反序列化,执行相反的操作:初始化一个循环运行 n 次(n 是流中的第一个整数),并在读取键/值对时添加到字典中。最后,检查你的常数。
Using keys and values of types that
BinaryReader
andBinaryWriter
handle, Write each Dictionary out to the BinaryWriter in key0,value0...keyN-1,valueN-1 order. Prefix this sequence with Dictionary'sCount
. After the sequence, write a constant to verify end of dictionary. Personally I like0xDEADBEEF
.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.