C# 中的关键字实现

发布于 2024-08-31 14:29:38 字数 218 浏览 3 评论 0原文

有没有办法,以及如何实现我自己的关键字,例如 inas (等),以在我的代码中使用?

这就是我的想法。我想(我想只是出于我个人的原因)添加一些我自己的关键字,其中之一是“was”关键字:

if(Control was Clicked)
{
   // etc etc
}

Is there a way, and how would I go about implementing my own keyword such as in, and as (etc), to be used in my code?

Here is what I had in mind. I want to (just for my own personal reasons, I guess) add a few keywords of my own, one of which would be the "was" keyword:

if(Control was Clicked)
{
   // etc etc
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

明明#如月 2024-09-07 14:29:38

不。

你能得到的最接近的是扩展方法:

Control.WasClicked()

No.

The closest you could get would be an extension method:

Control.WasClicked()
盛夏尉蓝 2024-09-07 14:29:38

不,您无法添加到 C# 语言,除非编写您自己的编译器。

但是,您的“was”关键字让我认为您可能正在寻找一种以声明方式处理事件的方法。 Microsoft 有一个名为“Reactive Extensions for .NET”的库(Rx )这是 LINQ 的扩展,允许您以声明方式处理事件。

No, you can't add to the C# language, short of writing your own compiler.

However, your "was" keyword makes me think you might be looking for a way to declaratively handle events. Microsoft have a library called "Reactive Extensions for .NET" (Rx) that is an extension to LINQ that allows you to deal with events in a declarative fashion.

燃情 2024-09-07 14:29:38

不,您不能向 C# 添加关键字 - 至少在不自己编写编译器的情况下不能。但是,如果您想要做的事情很简单,也许您可​​以使用自定义预处理器来完成。不过,您可能会失去 Visual Studio 中的一些语法突出显示和错误检查功能。

CLR 的一种语言被设计为可扩展,是 Boo

No, you cannot add keywords to C# - at least not without writing a compiler for yourself. If what you want to do is simple, however, perhaps you could do it using a custom preprocessor. You would lose some syntax highlighting and error checking in Visual Studio, though.

One language for the CLR, that is designed to be extensible like that, is Boo.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文