Renaming Controller Classes in MonoTouch MonoDevelop

What is the best way to rename the class that the UIViewController inherits and has the designer.cs class associated with the storyboard?

First I tried to rename the .cs file to MonoDevelop. This worked, but the designer.cs file did not receive a rename, and there was no class name.

Then I renamed the class name. This successfully changed the class name in the .cs and .designer.cs files, but did not change the .designer.cs file name. He also did not change the name "Custom Class" for the controller in Xcode.

So, in Xcode, I changed the name of the Custom Class and saved, and then switched to MonoDevelop, to my dismay, he created a new .cs with the same name as the renamed, and a new .designer.cs file, which he put under the original (renamed ) .cs file next to the old (not renamed) a.designer.cs file!

Can someone tell me the sequence of steps I should have taken?

+4
source share
4 answers

Renaming a file is difficult because MD does not support renaming grouped files. You will have to manually edit csproj or delete files from the project, rename it to Finder and add them back.

Renaming a class is somewhat simpler, but the key is to understand that the class actually has two names - the name .NET and the name Obj-C. Renaming a .NET name should be simple, you can just use the rename command in MD.

The name Obj-C applies to the attribute class [Register ("SomeName")] and is the name used in xib and in Xcode. However, be careful that MonoDevelop will try to create .NET copies of any classes that, in its opinion, were created in Xcode. This means that you must first change the name of Obj-C in MonoDevelop, and then switch to Xcode and change your own class there.

+4
source

You need to go into the .csproj file and add the tag. For instance:

<Compile Include="MainWindow.cs" /> <Compile Include="MainWindow.designer.cs"> <DependentUpon>MainWindow.cs</DependentUpon> </Compile> 

Then the correct relationship between the files in the MonoDevelop project window will be shown.

By the way, my experience so far is that this dependence is for convenience only. Add a new designer.cs file to the solution and the code simply compiles: the dependency seems to be some kind of documentation.

SEE ALSO: To delete or rename these dependent files, you cannot do this in the MonoDevelop project panel: you need to go to Finder (if you are in OSX, Explorer, if you are on Windows) and deal with files there to rename or otherwise manipulate them THEN edit the MonoDevelop csproj file manually. The good news is that it’s not difficult, and it works great when you do it and you get a great new hardcore understanding of how the project comes together.

+2
source

Many people also need to think about a version control system. This method works for me:

  • Exiting MonoDevelop
  • Rename files in version control system
  • Open the csproj file in a text editor - search and replace
  • Open MonoDevelop
  • Open XxxViewController.cs - search & replace
  • Open XxxViewController.designer.cs - do a search and replace
  • Open XxxViewController.xib - search & replace

You may be tempted to use Refactor / Rename instead of searching and replace it in step 5, but this will cause MonoDevelop to rename XxxViewController.designer.cs for XxxViewController_1.cs for some reason.

In addition, you may be tempted to delete files from the project before renaming them to the version control system and then adding them back to your project (so that you do not have to manually edit the csproj file). This will work, but the "DependentUpon" part will disappear from the csproj file, which will cause the designer file to not be lower than its counterpart. There is nothing complicated, but in the solution explorer it looks less pleasant.

0
source

I tried all of the above solutions and did not work. Finally, I just used Replace in Files, looking at the whole solution. After that I did "Rebuild" in the project and worked perfectly.

0
source

Source: https://habr.com/ru/post/1401353/


All Articles