Roslyn: Suggest format specifiers based on type

Created on 16 Mar 2019  路  7Comments  路  Source: dotnet/roslyn

Original developer community feedback

I have a TimeSpan object, which I need to convert into a string. When I typed ToString(""), I expected to see a list of common format specifiers with examples that I could use to autocomplete my line. Sadly, this is something that Resharper provides that I have come to rely on, and it's missing in Visual Studio 2019.

My example above speaks specifically to TimeSpan objects, but it applies generally to DateTime, numerics and any other type that accepts format specifiers, both as as an argument to ToString() and inside interpolated strings.

Intellisense suggests potential methods, events, properties, etc. I'm talking about suggestions for format specifiers when calling ToString().

Steps to Reproduce:

  1. Type the code below
DateTime.Now.ToString("

Expected Behavior:
When you type the quote (") you get a autocomplete suggestion like this:

t - short time                                               6:30
D - long date                             Thursday, 10 April 2008
d - short date                                         04/10/2008
F - full date long               Thursday, 10 April 2008 06:30:00
f - full date short                 Thursday, 10 April 2008 06:30
G - general long                              04/10/2008 06:30:00
.
.
(etc)

Just arrow down to the one you need and hit Enter.

Similar autocomplete suggestions are available for numeric types and TimeSpan, to name a few.

Area-IDE Feature Request InternalAsk help wanted

Most helpful comment

This could be done with the virtual-char service.

All 7 comments

This could be done with the virtual-char service.

@jinujoseph I would be interested in taking this on.

@CyrusNajmabadi sure, will appreciate help here

@jinujoseph Sorry, maybe in the future.

Resharper will do it.

Resharper will do it.

I don't use Resharper because it slows down VS on my work computer. Having this in vanilla VS would be great!

Resharper will do it.

I don't use Resharper because it slows down VS on my work computer. Having this in vanilla VS would be great!

Agree

Was this page helpful?
0 / 5 - 0 ratings