[英]C# Possible to overload operator ">" with Func<> on right side of operand?
I'm writing a fluent API (been upgrading EntitySpaces) and I want to have this syntax ...我正在编写一个流畅的 API(一直在升级 EntitySpaces),我想要这个语法......
EmployeeQuery q = new EmployeeQuery("q");
q.Select(q.Id > () => // Notice Func<> syntax here, this won't compile !!!!
{
return new EmployeeQuery("e", out var q1)
.Where(q1.Id.IsNotNull()).All();
})
);
But you guess it, compile error.但是你猜对了,编译错误。 I overload all of the operators in my syntax and everything works but I cannot get this syntax to work, I think the ">" followed by the "() =>" syntax just confuses the compiler entirely and it could never actually work?
我重载了语法中的所有运算符,一切正常,但我无法使此语法起作用,我认为 ">" 后跟 "() =>" 语法只会完全混淆编译器,它永远无法实际工作?
Note that above "q.Id" in the Select() methods returns an esQueryItem, thus the overload below ...请注意,Select() 方法中的“q.Id”上方返回一个 esQueryItem,因此下面的重载...
Here is my overload ...这是我的超载...
public class esQueryItem
{
public static esComparison operator >(esQueryItem item, Func<esDynamicQuery> func)
{
return null;
}
public static esComparison operator <(esQueryItem item, Func<esDynamicQuery> func)
{
return null;
}
}
Sinatr, you got it, thanx ... I don't want the last set of "()" because I don't want to execute the function, the function get's executed inside the Func<> itself, again thanx Sinatr,你明白了,thanx ...我不想要最后一组“()”,因为我不想执行该函数,函数 get 是在 Func<> 本身内部执行的,再次thanx
EmployeesQuery q = new EmployeesQuery("q");
q.Where(q.EmployeeID > (() =>
{
return new EmployeesQuery("e", out var q1)
.Select(q1.EmployeeID)
.Where(q1.EmployeeID.IsNotNull()).Any();
})
);
This generates ...这产生...
SELECT * FROM [Employees] q
WHERE q.[EmployeeID] > ANY
(
SELECT e.[EmployeeID]
FROM [Employees] e
WHERE e.[EmployeeID] IS NOT NULL
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.