As part of a C# class CsvConverter
that converts various file types to CSV, I am designing a private class CsvConversionResult
. My current design choice is to return a null
value of CsvConversionResult
if processing is successful.
What can I add to or remove from my design to use "best practices"? Returning primitive data types is out of the question since I want to return more than one thing.
public static class CsvConverter
{
public class CsvConverterError
{
public string Message { get; set; }
public int LineNumber { get; set; }
public string FileName { get; set; }
public CsvConverterError(string message, int lineNumber, string fileName)
{
Message = message;
LineNumber = lineNumber;
FileName = fileName;
}
}
// returns null if successful
public static CsvConverterError WriteCsvRowsToFile(char delimiter,
string inputFilePath,
string outputFilePath,
string qualifier = "")
{
CsvConverterError error = null;
/* Some code here that sets the value of error accordingly */
return error;
}
ConvertFile()
I want to return the line number, an error message, and the paths of the source and destination files, so the return type has to be a custom class. My current plan is that if the user of the class calls ConvertFile() and gets a CsvConverterSuccess object returned, they know from the method's <returns> XML tag that they have nothing more to do. Otherwise, they get a CsvConverterError object which holds information about where and what type of error occurred. \$\endgroup\$Success
. \$\endgroup\$CsvConverterError
's empty constructor which presumably should be setting those properties, you have things private which I'd have thought would need to be public. \$\endgroup\$