1

I have a noob question. When I use the built in visual studio "if" snippet the expression in the parentheses won't initially recognize any of the variables in my class. I have tried google without much luck.

Here are my steps to reproduce:

  1. I type "if" - the if statement snippet appears in my intellisense.
  2. I hit enter or tab - the if statement is added. There is now a red box inside the parentheses that says "expr".
  3. I now attempt to start typing my variable - nothing is found in the intellisense window. enter image description here

I have found that if I delete the red box and then move the cursor outside of the parentheses then go back inside the parentheses, the intellisense will then pick up the variable.

My question is: Is there a better way to use the if snippet with variables? Is this my my computer?

Talbert1209
  • 165
  • 1
  • 2
  • 10
  • 1
    This works fine for me. Have you tried closing and restarting VS? It tends to be a bit buggy at times :). – Jon Vote Nov 28 '18 at 22:31
  • Yeah I have. I still get the same results. I have visual studio on another computer at home. So I'll check when I get back there. – Talbert1209 Nov 28 '18 at 22:40
  • Also I am using VS2017. – Talbert1209 Nov 28 '18 at 22:40
  • 1
    Go to `Tools->Code Snippets->Manager-> Language: CSharp` and check if there is any snippet that is mapped to `if` – Xiaoy312 Nov 28 '18 at 22:48
  • 1
    Are you using ReSharper? – Jonathon Chase Nov 28 '18 at 22:57
  • @JonathonChase Yes. I am using ReSharper. – Talbert1209 Nov 29 '18 at 13:41
  • 2
    This is the ReSharper `if` live template being used over the default snippet that comes with VS. I'm not sure why it's intellisense is failing so hard. You can follow instructions [in this answer](https://stackoverflow.com/questions/21170329/disable-just-the-switch-snippet-in-resharper-8-c) substituting `if` for `switch`. Older version, but should hold up. – Jonathon Chase Nov 29 '18 at 16:19

1 Answers1

0

Thanks Jonathon Chase for pointing me in the right direction. This seems to be an issue with the ReSharper if live template. I would assume some folks like it better that way. Looking through the JetBrains documentation I was able to make the template work the way I wanted.

Here's what I did to fix this issue:

  1. Navigate to ReSharper > Tools > Templates Explorer
  2. Select C# and then find the if template (not the #if template)
  3. Change $expr$ to $expression$

Now save and it should work as expected.

Talbert1209
  • 165
  • 1
  • 2
  • 10