This is a console application which takes as an argument either a .cs file or a directory. If it's a .cs file, it scans it; if it's a directory, it scans all .cs files within the directory.
A simplified view of a method which chooses whether it's a file or a directory and reports errors is this one:
public static void ProcessPath(string path)
{
if (path.EndsWith(".cs"))
{
if (File.Exists(path))
{
Program.ScanFile(path);
}
else
{
Console.WriteLine("The specified file doesn't exist.");
Environment.Exit(1);
}
}
else
{
if (Directory.Exists(path))
{
Program.ScanDirectory(path);
}
else
{
if (File.Exists(path))
{
Console.WriteLine("The path corresponds to a file, but only *.cs files are supported.");
}
else
{
Console.WriteLine("The specified directory doesn't exist.");
}
Environment.Exit(1);
}
}
}
How can I rewrite the if/else
logic in a more elegant way? Would it improve readability?