C# 中的布尔聚合模式
我正在编写一个小查找应用程序,其中我有一个方便的控制台,可以快速查询缓存以进行完整性检查等。
也就是说,
get SomeField=Blue
这将从缓存中获取与该过滤器匹配的所有对象。
我可以应用更多过滤器,
get SomeField=Blue && SomeOtherField < 5
如果我决定支持 () ,这可能会变得更加复杂,
这里使用什么是好的模式?或者可能是一个可以接受字符串并为我标记它的组件?
例如,我想将以下内容分解为过滤器的子集
get ((field1=x || field1=y) && field2>x)
,我能想到的唯一方法是正则表达式,然后将子字符串传递给旨在创建特定过滤器的不同例程。 (即 AndEquals、OrEquals、AndGraterThan 等)
I am writing a little lookup app, where i have a console handy for quick queries against a cache for sanity checks etc..
i.e.
get SomeField=Blue
this will than get all objects from cache matching that filter.
I can apply more filters
get SomeField=Blue && SomeOtherField < 5
this can get more complex if i decide to support ()'s
what is a good pattern to use here? or possibly a component that can take a string and tokenize it for me?
for example, i'd want to break down the following into subset of filters
get ((field1=x || field1=y) && field2>x)
the only way i can think of doing this, is regex, and than pass off substrings to different routines designed to create a specific filter. (i.e. AndEquals, OrEquals, AndGraterThan etc)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
看看 IronPython。它很容易集成到 ac# 应用程序中,并且已经支持所有标准过程语言结构。我在游戏引擎中使用它来在调试时对场景状态进行实时调整。
Have a look at IronPython. It's easy to integrate into a c# app and already supports all standard procedural language constructs. I'm using it in a game engine to perform real-time tweaks to the scene state while debugging.
您不应该使用正则表达式来执行此操作,您需要一个成熟的解析器。看看 ANTLR。
You shouldn't do this with a regex, you need a full-blown parser. Have a look at ANTLR.
您可以在此处使用类似规范模式的内容。
完整的工作示例此处
You could use something like the Specification pattern here.
Full working example here