简体   繁体   English

如何使用 Resharper 文件/实时模板生成异常类

[英]How to use Resharper File/Live Templates to Generate Exception Class

I like to make a lot of custom exceptions for most error cases I run into, instead of say using InvalidOperation all the time.我喜欢为我遇到的大多数错误情况创建很多自定义异常,而不是一直使用 InvalidOperation。

I recently got Resharper and thought it's template functionality would be my savior, but I can't seem to get what I want out of the File/Live template function.我最近得到了 Resharper,并认为它的模板功能将是我的救星,但我似乎无法从 File/Live 模板功能中获得我想要的东西。

What I'm trying to do is essentially type this:我想要做的基本上是输入:

...
throw new [resharper key combo]MyCustomName[enter]
...

and get an exception class named 'MyCustomNameException' in file 'MyCustomNameException.cs'.并在文件“MyCustomNameException.cs”中获取名为“MyCustomNameException”的异常类。

Live templates doesn't seem to be the right thing for me -- that expands code inline.实时模板对我来说似乎不是正确的东西——它扩展了内联代码。 But file templates doesn't seem to either -- it only asks me to specify the name of the file.但是文件模板似乎也没有——它只要求我指定文件的名称。 Is the file template option as close as I can get to what I want here?文件模板选项是否尽可能接近我想要的内容?

Not sure about adding the 'Exception' part, but if you type the full name and press ALT + ENTER , ReSharper will offer to 'Create Class 'MyCustomNameException''.不确定是否添加“异常”部分,但如果您输入全名并按ALT + ENTER ,ReSharper 将提供“创建类“MyCustomNameException”。 The code it creates is:它创建的代码是:

internal class MyCustomNameException : Exception
{
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM