Hi,
I have a messy function that needs refactoring, it has too many nested IF's and it makes me nervous just to look at it!
Please ignore what the functions are doing, I'm more concerned with the structure/flow and how it can be refactored so it has less nested IF statements
The basic flow is as follows:
public static void HandleUploadedFile(string filename)
{
try
{
if(IsValidFileFormat(filename)
{
int folderID = GetFolderIDFromFilename(filename);
if(folderID > 0)
{
if(HasNoViruses(filename)
{
if(VerifyFileSize(filename)
{
// file is OK
MoveToSafeFolder(filename);
}
else
{
DeleteFile(filename);
}
}
else
{
DeleteFile(filename);
}
}
else
{
DeleteFile(filename);
}
}
else
{
DeleteFile(filename);
}
}
catch (Exception ex)
{
}
finally
{
// do some things
}
}