简体   繁体   中英

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.

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.

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'.

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''. The code it creates is:

internal class MyCustomNameException : Exception
{
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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