Issue with auto-property initializers when using C# 5.0 or lower

I have noticed that when performing a code cleanup that R# will use auto-property initializers where possible but R# will do this even in Visual Studio 2010.

Take for example the following code:

private static readonly Dictionary<string, CultureInfo> LanguagesDictionary = new Dictionary<string, CultureInfo> { ... }

public static Dictionary<string, CultureInfo> Languages
{
get
{
return LanguagesDictionary;
}
}

public static KeyValuePair<string, CultureInfo> DefaultLanguage
{
get
{
return Languages.First();
}
}

Which will be formatted by R# to an auto-property initialiser:

public static class SupportedLanguages
{
public static KeyValuePair<string, CultureInfo> DefaultLanguage
{
get
{
return Languages.First();
}
}

public static Dictionary<string, CultureInfo> Languages { get; } = new Dictionary<string, CultureInfo> { ... }
}

This results in several compiler errors:

I cannot find a setting in the R# options dialog that will allow me to disable auto-property initializers. Furthermore I have noticed that this only happens when the language version is set to default in the project settings (Build => Advanced):

When I set the language version to C# 5.0 or C# 4.0 then no auto-property initializers are used.

How can I make sure that R# does not use auto-property intializers without having to change the language version from "default" to C# 5.0 or lower?

For the time being I decorated my class with this:

[SuppressMessage("ReSharper", "ConvertToAutoProperty", Justification = "Reviewed. Suppression is OK here.")]

 

3 comments

Hello Gabriel!

 

R# adjusts it's features depending on language level specified in project Properties window ( View | Properties window) ReSharper | C# Language Level.

Changing ReSharper language level to C# 5 should help to resolve the problem.

Thank you.

0

Please sign in to leave a comment.