I wrote this code. It’s really ugly. I would like to refactor it. I MUST return a object[]. I was thinking maybe using a bool value to check if I have to move forward calling other methods and just having the final object[] creation.
private object[] TrasferisciSingoloFile(some parameters...)
{
Result result = new Result;
result = FTPRename(some parameters...);
if (result.error)
{
result.SetError("Some Problem 1");
object tip = new object[] { par as ThreadCounterManager, result };
return (object[])tip;
}
result = FTPDownloadAndCopy(some parameters...);
if (result.error)
{
result.SetError("Some Problem 2");
object tip = new object[] { par as ThreadCounterManager, result };
return (object[])tip;
}
result = FTPMove(some parameters...);
if (result.error)
{
result.SetError("Some Problem 3");
object tip = new object[] { par as ThreadCounterManager, result };
return (object[])tip;
}
result = FTPDelete(some parameters...);
if (result.error)
{
result.SetError("Some Problem 4");
object tip = new object[] { par as ThreadCounterManager, result };
return (object[])tip;
}
object tip1 = new object[] { par as ThreadCounterManager, result };
return (object[])tip1;
}
Let all the function of the suite FTPXXXX throw an exception when they found an error, so you can catch and return the error once in the
catch(){}block. The “some problem xxxx message” can be decorated with a message you provide in raising the exception.