This project is read-only.
1

Resolved

Simplify Type Name changes String to string and Int32 to int.

description

public static class MyClass
{
    private static readonly String myString = String.Empty;
}
Roslyn I believe is the one providing Simplify Type Name changes and in this example it suggests that both "String" identifiers be changed to "string". There is no performance advantage to using string instead of String since they both compile down to the same thing and the lower case version is no more simple (IMO) than the upper case version.

Also, the upper case version highlights as a type while the lower case version highlights as a keyword. In the case of primitives, they act/behave as types, not like flow control or declaration items so I believe the upper case version is a more reasonable choice from a syntax highlighting perspective.
public static class MyClass
{
    private static readonly UInt32 myString = UInt32.Empty;
}
In this case, "uint" is suggested as the simplified type yet from an enterprise development point of view UInt32 is more explicit and less likely to lead to an erroneous assumption, particularly by developers who may not come from an "int is 32-bits" world. The same thing occurs with Int32, UInt64, etc. In this case, not only do you lose the Type syntax highlighting as above, but you also lose the explicit sizing of the value in the typename. I want to believe that ECMA-335 intentionally did not use int, uint, long, etc. because they have lead to too much ambiguity in previous languages. C#s addition of them, I presume, was to allow easy transition from other languages but I do not believe it is a good idea to have the IDE recommend their usage over their more explicit counterparts.

comments

KrisVDM wrote Jun 24, 2014 at 8:06 AM

While my personal taste is to prefer int over Int32 in most situations, I have to admit that there are some issues with the simplification. For example, it also tends to remove explicit this. prefixes to members of the current type, or removing the current type name as a prefix for static members. This is a matter of style, taste and colors, and Visual Studio/Roslyn should not enforce a particular style in this space.

I think that "Simplify Type Name" should only do what its title suggests: removing redundant namespaces in the type name. Nothing else.

sharwell wrote Jun 24, 2014 at 11:57 AM

This should probably be an option. Since I prefer to use using alias declarations over using declarations for a namespace, even a single use of String or UInt32 forces the file to contain a new using declaration.

Pilchie wrote Jul 25, 2014 at 9:40 PM

In the VS "14" CTPs, we have added options to control this behavior under Tools\Options\Text Editor\C#\Formatting\Style.