System.Data.SQLite 扩展模型

发布于 2024-09-08 18:45:30 字数 297 浏览 0 评论 0原文

我想用 C# 实现 System.Data.SQLite 的函数。实现SQLiteFunction 接口很容易(在互联网上查看示例)。

问题是我应该把编译后的代码放在哪里?我是否需要将源代码与 System.Data.SQLite 项目一起编译?我是否有更好的选择,以便我的函数驻留在单独的 DLL 中?

说明:该函数不仅应该为我的 C# 代码所知,而且为 sqlite3 客户端(例如)所知,因此我将能够在执行 INSERT 时使用它以纯文本形式出现的命令。

I want to implement a function for System.Data.SQLite in C#. Implementing the SQLiteFunction interface is easy (seen examples over the Internet).

The question is where should I put the compiled code? Do I need the source to be compiled altogether with the System.Data.SQLite project? Do I have a better option, so that my functions will reside in a separate DLL?

Clarification: The function is supposed to be known not only for my C# code but also for sqlite3 client (for example), so I will be able to use it while executing INSERT commands that come in plain text.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

故乡的云 2024-09-15 18:45:30

SQLite 查看应用程序的所有程序集并识别具有[SQLiteFunction]属性的类型。因此,您可以将它们放在您喜欢的任何位置,只要在您第一次调用 SQLite 时该程序集已经加载即可。

如果它只是一两个函数,我倾向于将它们放入应用程序的现有程序集中之一。

SQLite looks at all of your application's assemblies and recognises types that have the [SQLiteFunction] attribute. So you can put them wherever you like, as long as that assembly is already loaded by the time you make your first SQLite call.

If it's just one or two functions I'd be inclined to put them in one of your application's existing assemblies.

北方的巷 2024-09-15 18:45:30

有一个静态方法SQLiteFunction.RegisterFunction,但文档说它是......

...目前不支持枚举程序集的 Compact Framework 的解决方法。

此外,据我所知,SQLiteFunctionAttribute 的文档如下:

一个简单的自定义属性,使我们能够在加载的程序集中轻松找到用户定义的函数,并在建立连接时在 SQLite 中初始化它们。

使用反射,枚举当前应用程序域中的所有程序集,查找具有 SQLiteFunctionAttribute 属性的类,并相应地注册它们。

所有用户定义的函数都会从所有加载的程序集中自动加载。

There's a static method SQLiteFunction.RegisterFunction, but documentation says that it's...

...a workaround for the Compact Framework where enumerating assemblies is not currently supported.

Additionally, from what I can tell based on documentation to SQLiteFunctionAttribute:

A simple custom attribute to enable us to easily find user-defined functions in the loaded assemblies and initialize them in SQLite as connections are made.

and

Using reflection, enumerate all assemblies in the current appdomain looking for classes that have a SQLiteFunctionAttribute attribute, and registering them accordingly.

all user-defined functions are loaded automatically from all loaded assemblies.

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