适用于 ReSharper 的 CodeRush 风格类型化模板

发布于 2024-12-22 19:45:45 字数 631 浏览 2 评论 0原文

我是 CodeRush 及其模板哲学的忠实粉丝。在我目前的工作中,我们将进行大量的配对,并且共识是对 ReSharper (v6) 的偏好,这几乎使我处于必须使用它的位置。

我不想在这里引发 CodeRush/Resharper 战争。 Resharper 有很多值得喜欢的地方,但在 ReSharper 中我很难克服一件事。

ReSharper 的 Live 模板机制虽然很好,但没有像 CodeRush 那样的内置输入概念(至少据我所知不是)。一个简单的例子如下。要生成以下代码:

public String MyStringProperty { get; set; }

在 CodeRush...我可以键入“as”(“a”代表 AutoProperty,“s”代表字符串),然后只需更改属性的名称。

在 ReSharper 中,我需要输入“prop”(属性),然后设置类型和名称。

ReSharper 的实时模板中似乎没有类似的类型感知或类型快捷方式概念。因此,似乎没有任何类似于大量的两个和三个字符模板来让您预先输入变量、属性、方法等......

所以,在所有背景之后,最后是问题。有没有办法在 ReSharper 中复制“类型化模板”的概念,而无需为每个模板/类型组合创建新的实时模板?

I'm a big fan of CodeRush and their philosophy around templates. At my current job, we'll be doing a large amount of pairing and the consensus is a preference for ReSharper (v6), which pretty much puts me in a place where I MUST use it.

I'm not looking to start a CodeRush/Resharper war here. There are plenty of things to like about Resharper, but there's one thing I'm having a hard time getting past in ReSharper.

ReSharper's Live template mechanism, wile good, doesn't have built-in notions for typing the way CodeRush does (at least not as I can tell). A simple example is as follows. To gen the following code:

public String MyStringProperty { get; set; }

In CodeRush...I could type "as" ('a' for AutoProperty and 's' for string), then simply change the name of the property.

In ReSharper, I need to type "prop" (for Property), then set the type and and name.

There does not seem to be a similar notion for type awareness or type shortcuts in ReSharper's Live Templates. As such, there doesn't appear to be anything akin to the numerous two and three character templates to get you pre-typed variables, properties, methods, etc...

So, finally the question after all that background. Is there any way to replicate this notion of "typed templates" in ReSharper without creating a new live template for every template/type combination?

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

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

发布评论

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

评论(2

我ぃ本無心為│何有愛 2024-12-29 19:45:45

目前,ReSharper 不支持您所指的使用模式。 但是,我可以想到两种选择来实现这一点。

  • 一种选择是为所有常见用例生成实时模板。我使用此文件,但请注意,它尚未使用 R 进行测试#6.1.
  • 另一种选择是简单地编写一个插件来执行此操作。 ReSharper SDK 有一个 HtmlZen 示例,它执行非常相似的操作,即将 DSL 字符串扩展为一段代码。您可以轻松地对助记符扩展执行相同的操作。

请注意,无论您选择哪个选项,您都无法通过按 空格 来展开模板 - 目前在 ReSharper 中这是不可能的。

如果您还有其他问题,请告诉我。

德米特里

Currently, ReSharper does not support the usage pattern you're referring to. However, there are two options I can think of to make this possible.

  • One option is to generate live templates for all common use cases. I use this file, but please note that it hasn't been tested with R#6.1.
  • Another option would be to simply write a plug-in to do this. The ReSharper SDK has a HtmlZen example that does something very similar, i.e. expand a DSL string into a piece of code. You could easily do the same for mnemonic expansion.

Note that whichever option you select, you won't get an ability to expand templates by pressing Space — this is simply not possible in ReSharper right now.

Please let me know if you have further questions.

Dmitri

樱花落人离去 2024-12-29 19:45:45

我认为不可能让 Resharper 拥有一个采用一个字母名称后跟一个字母类型的模板。您必须为每种类型创建一个新模板,例如“as”并将其定义为:

public string $NAME$ { get; set; }

您可能想要更改它的可用位置,即允许类型成员声明的 C# 文件。

您可以将“prop”模板重命名为“a”,然后输入:“a”、TAB、“s”、TAB、TAB、“property_name”、TAB

I don't think it's possible to get Resharper to have a template that takes a one letter name followed by a one letter type. You will have to create a new template for each type, e.g. 'as' and define it as:

public string $NAME$ { get; set; }

You may want to change where it is available, i.e. C# files where type member declaration is allowed.

You could rename the 'prop' templete to just 'a', then you would type: 'a', TAB, 's', TAB, TAB, 'property_name', TAB

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