R# not offering to initialise property.

Completed

http://recordit.co/4SbDI0FeOq

R# offers to initialise two of three properties from the ctor parameters but offers to create a field for one of them. It looks like it wants to map 'id' to 'ID' and consequently ignores the fact that there is already an 'Id' property.

I am using the latest EAP.

4 comments
Comment actions Permalink

Hello Aruecope,

I tried to reproduce this issue but without success. Could you please try clearing caches for the solution as described here?

If the issue still happens, could you reproduce the same behavior in a newly created solution and send it to me? You can use the "Submit a request" button above.

Also, ReSharper can help you create a constructor using the Generate feature (ReSharper | Edit | Generate Code | Constructor). Choose the Constructor item in the menu and select all properties, you want to initialize. ReSharper will do the rest. Here you can read more about Generate Type Constructors.

0
Comment actions Permalink

I was easily able to replicate it. I can send the solution but all I did was create a .NET 5 console application and add a class to program.cs:

namespace ConsoleApp5
{
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}

class wibble
{
public wibble(int id)
{ }

public int Id { get; }
}
}

 

0
Comment actions Permalink

Ah ha! I've found the reason. We had 'ID' defined as an abbreviation. I've no idea why/how though because we discussed it several years ago and despite most of us preferring 'ID' we decided to follow convention and go with CamelCase. It seems like R# could've been more helpful - maybe

'Initialize auto-property 'Id' and rename to abbreviation 'ID'' in the action menu?

I mean you're technical support for R# and the cause wasn't obvious to you either ;)

1
Comment actions Permalink

Hello Aruecope,

I'm glad to hear you found the reason for such behavior. After adding an ID abbreviation, I reproduced it.
I discussed your suggestion about the new quick fix with our development team and we consider such a case is too rare to create a separate quick fix.
Thank you.

0

Please sign in to leave a comment.