This is legacy, so I'm not really looking for improvements on architectural approach.
Here's what the method does:
- Extracts filename from a string containing full file path (passed in as parameter)
- Checks to see if the filename extracted is not null or empty or just white spaces
If check in step 2 passes, then it uses naming conventions in the filename, to determine the logical "Type" for the file as follows:
- If filename contains
__Import__
, then setType
toSource Data
- If filename contains
__Export__
, then setType
toDestination Data
- If filename contains
__Transform__
, then setType
toTransformational Data
- If none of the conditions from 3.1 through 3.3 are met, then default the "Type" to
General
.
- If filename contains
Is there a way to make the if...else if... else if...
block more concise, and elegant without loss of functionality?
private static string GetFileDataType(string fullFileNameWithPath)
{
// extract filename only
var fileName = Path.GetFileNameWithoutExtension(fullFileNameWithPath);
var fileDataType = string.Empty;
// if filename is not empty
if (!string.IsNullOrWhiteSpace(fileName))
{
// if... else... to determine type of file contents based on file name convention
// legacy code, so not looking for architectural improvements etc... :)
if (fileName.Contains("__Import__"))
{
fileDataType = "Source Data";
}
else if (fileName.Contains("__Export__"))
{
fileDataType = "Destination Data";
}
else if (fileName.Contains("__Transform__"))
{
fileDataType = "Transformational Data";
}
else
{
fileDataType = "General";
}
}
return fileDataType;
}