Hi,
I have the following ugly if statement that is part of a class that is pulled from an IOC container:
protected virtual void ExecuteSourceControlGet(IBuildMetaData buildMetaData, IPackageTree componentTree)
{
if ((buildMetaData.RepositoryElementList != null) && (buildMetaData.RepositoryElementList.Count > 0))
{
componentTree.DeleteWorkingDirectory();
foreach (var repositoryElement in buildMetaData.RepositoryElementList)
{
repositoryElement.PrepareRepository(componentTree, get).Export();
}
}
if((buildMetaData.ExportList != null) && (buildMetaData.ExportList.Count > 0))
{
var initialise = true;
foreach (var sourceControl in buildMetaData.ExportList)
{
log.InfoFormat("\nHorn is fetching {0}.\n\n".ToUpper(), sourceControl.Url);
get.From(sourceControl).ExportTo(componentTree, sourceControl.ExportPath, initialise);
initialise = false;
}
}
log.InfoFormat("\nHorn is fetching {0}.\n\n".ToUpper(), buildMetaData.SourceControl.Url);
get.From(buildMetaData.SourceControl).ExportTo(componentTree);
}
My normal approach to eliminating if statements is to create a subclass for each condition.
What is different about this example is:
- The class that has this method is pulled from the IOC container.
- I might want the logic in between the 2 if statements to run or not at all.
Any advice greatly welcomed.
Cheers
Paul