EBNF 到流畅界面
我最近需要为 C# 编写一个流畅的接口,该接口本质上是 SQL 的镜像。 是的,我知道 LINQ to SQL,但我对“更接近金属”感兴趣——拥有本质上只在 C# 中提供 Intellisensified SQL shim 的东西。
例如,
var fq = new FluentQuery();
Expression<Action> =
() => fq.SELECT.DISTINCT(Foo.ID).FROM(Foo).WHERE(Foo.Age > 22);
现在,我在想这个概念可以推广——也就是说,一个通用的 EBNF 到流畅的接口生成器怎么样? 有谁知道这样的野兽是否存在?
I have recently had the need to write a fluent interface for C# that will essentially mirror SQL. Yes, I am aware of LINQ to SQL, but I'm interesting in getting "closer to the metal"--having something that essentially provides nothing more than an Intellisensified SQL shim within C#.
E.g.,
var fq = new FluentQuery();
Expression<Action> =
() => fq.SELECT.DISTINCT(Foo.ID).FROM(Foo).WHERE(Foo.Age > 22);
Now, I was thinking that this concept could be generalised--that is, how about a general EBNF to fluent interface generator? Does anyone know if such a beast exists?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我喜欢它,但你必须确保返回像 HasFromAndSelect 或类似的类型,这样你就不会最终得到
fq.SELECT(Foo.ID).SELECT(Foo.Age).WHERE(Foo. Age > 22)
或fq.WHERE(Foo.Age > 22).SELECT(Foo.ID)
等。还有更多的事情需要考虑,包括事实上,大写锁定模式正在伤害我的眼睛:)
I like it, but you have to make sure to return types like HasFromAndSelect or something like that so you don't end up with
fq.SELECT(Foo.ID).SELECT(Foo.Age).WHERE(Foo.Age > 22)
orfq.WHERE(Foo.Age > 22).SELECT(Foo.ID)
, etc.There's much more thought that needs to go into this, including the fact that the CAPS LOCK MODE is hurting my eyes :)