在 C# 中序列化和反序列化表达式树
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/217961/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Serializing and Deserializing Expression Trees in C#
提问by Alexandre Brisebois
Is there a way to Deserialize Expressions in C#, I would like to store Expressions in a Database and load them at run time.
有没有办法在 C# 中反序列化表达式,我想将表达式存储在数据库中并在运行时加载它们。
采纳答案by T. Webster
I continued work on the library that was mentioned by Serializing and Deserializing Expression Trees in C#
我继续研究Serializing and Deserializing Expression Trees in C# 中提到的库
It looks like the project was abandoned (2008) but I did some work on it and now it works with .NET 4.0 and Silverlight. I made bug fixes to their code and also made it more DAL-independent.
看起来该项目已被放弃(2008 年),但我做了一些工作,现在它可以与 .NET 4.0 和 Silverlight 一起使用。我对他们的代码进行了错误修复,并使其更加独立于 DAL。
回答by Marc Gravell
Not in full; however, the Dynamic LINQsample may help a bit. You can certainly serialize an expression to a string (to an extent - generics look a bit screwy), but there is no inbuilt parser.
不完整;但是,动态 LINQ示例可能会有所帮助。您当然可以将表达式序列化为字符串(在某种程度上 - 泛型看起来有点奇怪),但没有内置的解析器。
回答by Pop Catalin
There's an project on GitHub/Nuget called MetaLinqthat aims to make working with expression tress more easy.
GitHub/Nuget 上有一个名为MetaLinq的项目,旨在让使用表达式发束更容易。
It converts between normal Expressions and 'EditableExpressions' which are mutable and fully Serializable, so can be used with Json, Xml, Binary etc.
它在普通表达式和可变且完全可序列化的“EditableExpressions”之间进行转换,因此可以与 Json、Xml、Binary 等一起使用。
Also check this blog postfor more info.
另请查看此博客文章以获取更多信息。
回答by Rich
Other option is the Expression Tree Serializationproject on code.msdn.com - would appear to be more what is needed here?
其他选项是code.msdn.com 上的Expression Tree Serialization项目 - 这里似乎更需要什么?
UPD: Now http://archive.msdn.microsoft.com/exprserialization
回答by Jonathan Parker
WCF RIA Services allows for serializing IQuerayble<T>
WCF RIA 服务允许序列化 IQuerayble<T>
回答by esskar
have a look at my new library Serialize.Linq. It serializes linq expressions to json, xml and binary.
看看我的新库Serialize.Linq。它将 linq 表达式序列化为 json、xml 和二进制文件。
回答by Mohammad Dayyan
I was working on a project for serializing expressions. It's OK and you can use it. http://www.codeproject.com/Articles/851187/ServicePredicateBuilder-for-creating-Serializable
我正在研究一个序列化表达式的项目。没关系,你可以使用它。 http://www.codeproject.com/Articles/851187/ServicePredicateBuilder-for-creating-Serializable