Visual Studio / C# 编译器扩展:LinQ "either X or Y"

Visual Studio / C# compiler extension: LinQ "either X or Y"

有没有办法为 VS 2017 或 Roslyn 编译器或其他任何东西创建某种扩展,以使这个 LinQ 查询更漂亮一些?

var query = from s in db.TimeSlicedPosts
            where s.Post == post || s.Post == null
            where s.Date == day
            where s.Hour == hour
            select s;

我希望它看起来像这样:

var query = from s in db.TimeSlicedPosts
            where either s.Post == post or s.Post == null
            where s.Date == day
            where s.Hour == hour
            select s;

由于两个或多个 where 子句创建了一个 AND 条件,我希望有一个英语格式的方式来创建一个 OR 条件也是如此,在这种情况下,either X or Y [or Z, ...].

是否有可能以这种方式制作它,以便后一个示例将被视为完全有效的 C# 代码,而无需重新编写和重新编译 Roslyn,而是通过编写某种扩展?

如果是,那我应该从哪里开始挖掘呢?

No, Roslyn doesn't allow you to add plugins to change the grammar of C#. You could fork Roslyn to create your own dialect, but I'd strongly advise against it. Aside from anything else, almost all professional C# developers will be able to read and write your first code. You'd have to explain your own custom dialect to everyone who wanted to use your second code.

Jon Skeet