3

Note: I assumed I didn't have to make this any clearer, but this question is not about renaming the parameters in a tuple, it's about renaming the parameters' types.

For example:

public class Foo
{
    public static (Foo, Foo) GetTuple() => (new Foo(), new Foo());
}

If I put the cursor on either Foo inside the tuple return type and invoke the refactor > rename functionality, I get the familiar error "You cannot rename this element". Why?

I understand there are complexities around renaming tuple parameters themselves, if used, e.g. first and second in (Foo first, Foo second), but those complexities definitely do not extend to the types of the parameters.

enter image description here

rory.ap
  • 34,009
  • 10
  • 83
  • 174
  • i think VS just doesn't support renaming tuple types used as return types or method parameters, probably due to how the C# compiler handles internal tuple types – Mayfair Apr 30 '23 at 16:25
  • @dbc They are hard-coded as Item1 and Item2, but _their types are not_. There is nothing changing the name `Foo` to `Item1`, that's just not happening. – rory.ap Apr 30 '23 at 16:48
  • @dbc please see note I added at the top of the question. – rory.ap Apr 30 '23 at 16:51
  • 1
    Just to be clear, what you want to do is to right-click on the `Foo` in `(Foo, Foo)` and rename the type `Foo` to something else, say `Bar`, and have it renamed everywhere, so `GetTuple()` now returns `(Bar, Bar)` not `(Foo, Foo)`, but you can't because the option isn't provided? If so, it seems like one of those [features are unimplemented by default](https://stackoverflow.com/a/8673015) scenarios where MSFT has not written the special-case code required to do it. – dbc Apr 30 '23 at 17:16
  • There is a long standing GitHub issue for this it seems https://github.com/dotnet/roslyn/issues/14115 – Timothy G. May 01 '23 at 12:06
  • @TimothyG. No, that's not it. That's about renaming the parameters, not about renaming their types. I can't understand why people are having such trouble understanding the difference between a variable and its type. – rory.ap May 01 '23 at 13:03
  • Hello, your issue does exist under my reproduction. I've submitted it to the Visual Studio Improvement Program. You can also get more timely help on [Visual Studio Feedback Platform](https://developercommunity.visualstudio.com/VisualStudio/report?port=1025&fsid=919abe62-0462-40f1-8ee4-b0278c99530a). – wenbingeng-MSFT May 02 '23 at 07:59

1 Answers1

-1

You cannot rename something and expect everywhere to change recursively upward. You can always rename from class Foo but if you try to rename Foo from the tuple inside the Foo class, this action confuses Visual Studio and results in losing the reference location.

Timothy G.
  • 6,335
  • 7
  • 30
  • 46