1

I'm looking for a way to easily replace all CLR-Type references in a codebase with a few thousand files with their respective alias types, specifically:

  • "Int64" => "long"
  • "Int32" => "int"
  • "Int16" => "short"
  • "UInt64" => "ulong"
  • "UInt32" => "uint"
  • "UInt16" => "ushort"
  • "Double" => "double"
  • "Single" => "float"
  • "Decimal" => "decimal"
  • "Byte" => "byte"
  • "SByte" => "sbyte"
  • "Object" => "object"
  • "String" => "string"
  • "Char" => "char"
  • "Boolean" => "bool"

I've found this tool AliasBeGone that does it the other way around and is for older visual studio versions and only for a single file at a time. Is there a tool out there that can do what I'm trying to achieve or is it best if I keep trying to make a solution of my own using either a console application or a bash script?

If anyone could point me in the right direction that would be much appreciated.

8
  • 1
    Resharper/Rider can do this. Commented Sep 6, 2023 at 12:44
  • Can you open the codebase in Visual Studio? Commented Sep 6, 2023 at 12:45
  • 1
    Related: string vs. String is not a style debate. Commented Sep 6, 2023 at 13:30
  • 1
    BTW, main problem here would be to avoid wrong replacements. Doing things automatically might cause replaces you really shouldn't have done (written from the perspective of a painful experience). Be careful. Commented Sep 6, 2023 at 13:32
  • 1
    No need, hover the mouse cursor over a CLR-type, you will see a similar popup. Commented Sep 6, 2023 at 14:10

1 Answer 1

0

For the sake of completeness if anyone else has the same issue I'll post this as an answer here.

As shingo pointed out this can be achieved with Visual Studio using a similar popup from a previous answer of theirs.

This popup should appear when you hover over a CLR type and you can replace all occurrences in the solution. If this popup doesn't appear you should check your solutions .editorconfig file.

Make sure the following lines are included there:

  • dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion
  • dotnet_style_predefined_type_for_member_access = true:suggestion

Then it should work. If anyone has a better solution please feel free to post it here too.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.