I have a problem with a newly installed Visual Studio 2008 (new pc) and ReSharper 4.5.
Edit: Issue opened at: http://www.jetbrains.net/jira/browse/RSRP-107956.
I have the following code:
public static TValue GetOrCreate<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, TKey key)
where TValue: new()
{
#region Parameter Validation
if (ReferenceEquals(null, key))
throw new ArgumentNullException("key");
#endregion
TValue result;
if (dictionary.TryGetValue(key, out result))
return result;
result = new <-- problem here
dictionary.Add(key, result);
return result;
}
The line marked as the problem is where I'm having problems.
When I type this (| marks the point of my cursor):
result = new |
then I get an intellisense dropdown with TValue in it, and it is selected.
No matter what I type now, this is what I end up with:
result = new _ (|);
again, | marks the cursor position. There are a couple of problems here:
- Regardless of what I type, a tab-character is inserted after the underscore, not two spaces as I had to use above.
- I've turned off the addition of parenthesis and brackets on completion, but they're still added for this particular construct
- It seems to be impossible to get ReSharper to insert the type selected, it just adds an underscore instead (no, the underscore is not my way of saying "type goes here", it expands to exactly what I showed above, without the type, but with an underscore + Tab-character instead)
Keys I've tried hitting when the intellisense is up:
- Space (difference: parenthesis looks like this: ( |), ie. a space added)
- Tab
- Enter
- ( - that is, opening parenthesis
- T+any of the above (ie. type out the first letter of TValue and hope that helps, which it doesn't)
The only thing that "helps" is if I hit one of the keys that switches to the fuller intellisense dropdown, like the default Alt-Right, then it just adds lots more things I can select, still has TValue selected, but now if I hit Enter or Tab, the code is expanded correctly.
Does anyone know what I need to tweak?
Edit: Before I posted, I thought about the method and decided that the parameter validation there is probably not needed, so I took it away, and lo and behold, now it auto-completes correctly.
Is this just a(nother) bug in ReSharper?
Note that if I write the code correctly on that line, ie. write TValue instead of the underscore, the project builds.
Edit: Note, there are no live templates in ReSharper that are enabled, that was the first thing I disabled, just to test if there was a weird template that overrode my selection.