So my question is more about what I should do, not necessarily 'how' to implement what I'm doing. So, I have this static class that looks like this:
public static class CanImportFileType
{
static Predicate<string> isSTQFile = f => f.ToLower().EndsWith(".stq") || f.ToLower().EndsWith(".stqt");
static Predicate<string> isAPHFile = f => f.ToLower().EndsWith(".aph");
public static bool IsValidQuoteFilePath(string[] FilePath)
{
bool IsValidQuoteFilePath = false;
if(HasFile(FilePath))
{
if(isSTQFile(FilePath[0]))//we just look at the first index...we could extend this to look through all of the indices and find the first appropriate
{
IsValidQuoteFilePath = true;
}
}
return IsValidQuoteFilePath;
}
public static bool IsValidQuoteFilePath(string FilePath)
{
bool IsValidQuoteFilePath = false;
if (isSTQFile(FilePath))
{
IsValidQuoteFilePath = true;
}
return IsValidQuoteFilePath;
}
public static bool IsValidAPHFilePath(string[] FilePath)
{
bool IsValidQuoteFilePath = false;
if (HasFile(FilePath))
{
if(isAPHFile(FilePath[0]))
{
IsValidQuoteFilePath = true;
}
}
return IsValidQuoteFilePath;
}
public static bool IsValidAPHFilePath(string FilePath)
{
bool IsValidQuoteFilePath = false;
if (isAPHFile(FilePath))
{
IsValidQuoteFilePath = true;
}
return IsValidQuoteFilePath;
}
/// <summary>
/// used only to determine if the string array being passed around is not null or void of any strings (count == 0)
/// </summary>
/// <param name="fileLocation"></param>
/// <returns> whether or not there is a file type in the first index of a string array</returns>
private static bool HasFile(string[] fileLocation)
{
bool hasfile = false;
if (fileLocation != null)
{
if (fileLocation.Count() > 0)
{
hasfile = true;
}
}
return hasfile;
}
}
Now to implement this I would have something like this:
string[] foo = {"hello", "world"};
CanImportFileType.IsValidQuoteFilePath(foo) //returns false
Or, I could just extend the string[] and string types with adding a 'this' keyword at the beginning of the method arguments which would look something like this:
public static bool IsValidQuoteFilePath(this string[] FilePath)
{
bool IsValidQuoteFilePath = false;
if(HasFile(FilePath))
{
if(isSTQFile(FilePath[0]))//we just look at the first index...we could extend this to look through all of the indices and find the first appropriate
{
IsValidQuoteFilePath = true;
}
}
return IsValidQuoteFilePath;
}
Then, all I would have to do to implement it would be to access that strings IsValidQuoteFilePath method like such:
string[] foo = {"hello", "world"};
foo.IsValidQuoteFilePath() //returns false
I guess to summarize my question it would be: How do you know when to just extend a method versus creating a static helper class?