Bug 39513 - Refactor Initialize Field from Parameter is generating wrong code
Summary: Refactor Initialize Field from Parameter is generating wrong code
Status: RESOLVED FIXED
Alias: None
Product: Xamarin Studio
Classification: Desktop
Component: C# Binding ()
Version: 6.0.0 (C7)
Hardware: Macintosh Mac OS
: Normal normal
Target Milestone: (C7)
Assignee: Mike Krüger
URL:
Depends on:
Blocks:
 
Reported: 2016-03-10 12:43 UTC by Stefan de Vogelaere
Modified: 2016-05-16 17:48 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Stefan de Vogelaere 2016-03-10 12:43:06 UTC
Description of Problem:

The generated code for the refactoring "Initialize field from Parameter" is not correct.

Steps to reproduce the problem:

Add ILogger logger to a constructor.
Use Refactor => Initialize field from Parameter

Actual Results:

this._logger = _logger;

Expected Results:

this._logger = logger;

Additional Information:


=== Xamarin Studio ===

Version 6.0 (build 4761)
Installation UUID: 12fe90a2-25a8-42b6-a512-e89c31c1ba8a
Runtime:
	Mono 4.3.2 (mono-4.3.2-branch/ba2e5e4) (64-bit)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 403020467

=== Build Information ===

Release ID: 600004761
Git revision: 6913a43555e7434103860008ffa7d913d22819a7
Build date: 2016-03-08 15:54:12-05
Xamarin addins: 866256c8c5c8db3a07af37b579375505d5d88729
Build lane: monodevelop-lion-cycle7
Comment 1 Mike Krüger 2016-03-11 13:01:03 UTC
Can't verify with current version:

class EmptyClass
{
	public EmptyClass (object logger)
	{
	}
}

results in:

class EmptyClass
{
	readonly object logger;

	public EmptyClass (object logger)
	{
		this.logger = logger;
	}
}
-----------------

I only get this._logger = _logger; if the parameter is named _logger. Can you provide more info about this issue ?
Comment 2 Stefan de Vogelaere 2016-03-11 15:28:30 UTC
I think you need to change naming conventions first.

I want all private and readonly fields to be prefixed with _.
So I change Naming Conventions based upon MONO style.
Then I change "Fields (Private)" settings to have Prefix _ instead of the Optional Prefixes (clean it) and choose camelCase. I do the same for ReadOnly Fields (Private).

After that, when I perform your code it generates this._logger = _logger;
Comment 3 xamarin-release-manager 2016-03-14 10:42:55 UTC
Fixed in version 6.1.0.255 (master)

Author: Mike Kr??ger
Commit: 81ca67af84662eea7fdfe5c3633b3ef666d21bdf (mono/monodevelop)
Comment 4 xamarin-release-manager 2016-03-14 10:44:07 UTC
Fixed in version 6.0.0.4791 (cycle7)

Author: Mike Kr??ger
Commit: afbeac8293d32bca31ea8745e0b29b0afcc844e9 (mono/monodevelop)
Comment 5 xamarin-release-manager 2016-04-01 14:50:51 UTC
Fixed in version 6.0.0.4918 (cycle7-android-n)

Author: Mike Kr??ger
Commit: afbeac8293d32bca31ea8745e0b29b0afcc844e9 (mono/monodevelop)
Comment 6 Abhishek 2016-05-16 17:48:23 UTC
I have checked this issue but I am unable to reproduce this issue given in the bug description.

I am getting the behavior mention on the comment 1.  

I have checked this issue with latest C7 build:
XamarinStudio-6.0.0.5156_6bb41168165682b4ed22a94364bf0cf24e6b1d5c. 

Screencast: http://www.screencast.com/t/3oBjb8ylNxl

Just let me know whether I am following the correct steps to verify this issue at my end.

Thanks!