SQL Server CLR 聚合:序列化字典?

发布于 2024-12-27 21:07:31 字数 212 浏览 3 评论 0原文

我正在用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

粉红×色少女 2025-01-03 21:07:31

使用 BinaryReaderBinaryWriter 处理的类型的键和值,按 key0、value0...keyN-1、valueN-1 的顺序将每个字典写入 BinaryWriter。在此序列前添加字典的 Count 前缀。在序列之后,写入一个常量来验证字典的结尾。我个人喜欢0xDEADBEEF

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

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.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文