-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Description
Version Used: 17.14.13 (August 2025)
Steps to Reproduce:
-
Have code in a file where anonymous type is constructed using explicit names even if they could be inferred
using System; namespace TestConsoleApp.Original; public class AnonymousTypeUsage { public object MakeAnonymousTypeValue() { return new { Now = DateTime.Now }; } }
-
Ensure that anonymous type member name inference is not preferred
-
Move the file to a different namespace and confirm the 'Adjust namespaces for moved files' dialogue
Diagnostic Id: IDE0037 Use inferred member name
Expected Behavior:
The namespace should be updated without preferably changing anything else in the file. But if it does change something, it should be according to the style rules.
Actual Behavior:
The explicit anonymous type names are gone (comment mine):
using System;
namespace TestConsoleApp.Different;
public class AnonymousTypeUsage
{
public object MakeAnonymousTypeValue()
{
return new { DateTime.Now }; // <-- 'Now = ' was deleted
}
}
Additional remarks:
The Now
property is shown as greyed-out and suggesting a removal even with the Visual Studio setting set to 'No':
Note that there is no .editorconfig anywhere that I know of, but if I add one with
[*.cs]
dotnet_style_prefer_inferred_anonymous_type_member_names = false
the property is no longer greyed out and removal of the member name is no longer offered:
Moving the file and adjusting namespace still removes the member name, though, regardless of the .editorconfig setting. It would be nice if the setting worked consistently in VS, but my main issue is the unprompted removal when updating namespaces for moved files.