是否有第 3 方库知道将 linq 表达式转换为人类可读的字符串表示形式?

发布于 2024-09-27 04:40:26 字数 755 浏览 1 评论 0原文

我有一个 linq 表达式,我希望以人类可读的形式在日志中显示它。有人知道哪个图书馆可以做到这一点吗?我看到了这个条目从 lambda 表达式创建字符串,但它在我看来,没那么有用。

谢谢。

编辑

现在我想了一下,我的情况可能不具有代表性,因为我的 linq 表达式内部包含一个类型名称,它被 ToString 扩展为完全可怕的东西,因为该类型是泛型一。例如,表达式e => e.TypeName == typeof(T).AssemblyQualifiedName 其中 T 是我的通用上下文扩展为:

"e => (e.TypeName == \"Shunra.Infra.DummyEntity.Contract.IDummyEntity`1[[System.Object, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], Shunra.Infra.DummyEntity.Contract, Version=1.0.0.0, Culture=neutral, PublicKeyToken=807fc02bc4ce69db\")"

看起来要求程序集限定名称的格式良好一点也不公平......

I have a linq expression and I wish to display it in the log in a human readable form. Any one knows any library that can do it? I saw this entry Creating a string from a lambda expression, but it is not that useful, in my opinion.

Thanks.

EDIT

Now that I think about it, my case is probably not that representative, because my linq expression includes a type name inside, which is expanded by the ToString to something totally monstrous, because the type is a generic one. For example, the expression e => e.TypeName == typeof(T).AssemblyQualifiedName where T is my generic context is expanded to:

"e => (e.TypeName == \"Shunra.Infra.DummyEntity.Contract.IDummyEntity`1[[System.Object, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], Shunra.Infra.DummyEntity.Contract, Version=1.0.0.0, Culture=neutral, PublicKeyToken=807fc02bc4ce69db\")"

Looks like demanding that the assembly qualified name be nicely formatted is not fair at all...

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

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

发布评论

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

评论(1

黑寡妇 2024-10-04 04:40:26

您可以只使用 ToString,输出是相当可读的,至少对于程序员来说......

You can just use ToString, the output is fairly readable, at least to a programmer...

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