2 Replies - 817 Views - Last Post: 27 September 2012 - 08:44 PM Rate Topic: -----

#1 khumeniuk  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 21-September 12

Refactoring some small code

Posted 21 September 2012 - 04:55 AM

object[] projectName = excelService.GetRangeA1(excelFilePath, Constants.SheetName, ResourceHelper.ExcelProjectNameColumn, false, out wsStatus);
            object[] idName = excelService.GetRangeA1(excelFilePath, Constants.SheetName, ResourceHelper.ExcelIDColumn, false, out wsStatus);
            object[] scoreName = excelService.GetRangeA1(excelFilePath, Constants.SheetName, ResourceHelper.ExcelScoreColumn, false, out wsStatus);

Does anyone know how I can solve so as do not to be used several times object [] and other variables that are duplicates, of course, so as to obtain the values ​​of variables of type object []

Is This A Good Question/Topic? 0
  • +

Replies To: Refactoring some small code

#2 tlhIn`toq  Icon User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6317
  • View blog
  • Posts: 13,916
  • Joined: 02-June 10

Re: Refactoring some small code

Posted 21 September 2012 - 05:43 AM

This is meaningless to us. We have no way of knowing how many times these are used throughout your program. You can't refactor JUST the 3 fields. For all we know all of these are used 1,000 times each throughout your program.
Was This Post Helpful? 2
  • +
  • -

#3 immeraufdemhund  Icon User is offline

  • D.I.C Regular

Reputation: 79
  • View blog
  • Posts: 495
  • Joined: 29-March 10

Re: Refactoring some small code

Posted 27 September 2012 - 08:44 PM

well based on what you have given us (and as mentioned earlier, isn't much) from what i can see you do have a duplicate method. What I mean is that you call the same method 3 times and get back 3 object[]. Now I'm not sure how you use the data, so to make sure it still works i have to keep that output. But if you knew what the desired variable back was it would be an easy change. this is my approach to your refactoring. I did not compile or test my code, but the idea behind it is their. Once I know what desire object type is I can change my structure to match the data type, then I can change my one function to return that type of data. That would be the only changes needed for this exercise. I hope this helps.

struct ExcelNames
	public object[] projectName;
	public object[] idName;
	public object[] scoreName;

public object[] GetExcelName(ResourceHelperColumn column)
	string wsStatus = "";
	object[] returnValue = excelService.GetRangeA1(excelFilePath, Constants.SheetName, column, false, out wsStatus);
	//check return value from wsStatus???
	return returnValue;

public void ThingToRefactor()
	ExcelNames names = new ExcelNames();
	names.projectName = GetExcelName(ResourceHelper.ExcelProjectNameColumn);
	names.idName = GetExcelName(ResourceHelper.ExcelIDColumn);
	names.scoreName = GetExcelName(ResourceHelper.ExcelScoreColumn);

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1