In C# I have the following two extension methods.
public static void WaitForMilliseconds(this IWebDriver driver, int milliseconds)
{
var timeout = new TimeSpan(0, 0, 0, 0, milliseconds);
WaitForTimeout(driver, timeout);
}
public static void WaitForSeconds(this IWebDriver driver, int seconds)
{
var timeout = new TimeSpan(0, 0, 0, seconds);
WaitForTimeout(driver, timeout);
}
private static void WaitForTimeout(IWebDriver driver, TimeSpan timeout)
{
try
{
new WebDriverWait(driver, timeout).Until(x => false);
}
catch (Exception){}
}
But since the class is static, I can write a private extension method to make the syntax more readable like this.
public static void WaitForMilliseconds(this IWebDriver driver, int milliseconds)
{
var timeout = new TimeSpan(0, 0, 0, 0, milliseconds);
driver.WaitForTimeout(timeout);
}
public static void WaitForSeconds(this IWebDriver driver, int seconds)
{
var timeout = new TimeSpan(0, 0, 0, seconds);
driver.WaitForTimeout(timeout);
}
private static void WaitForTimeout(this IWebDriver driver, TimeSpan timeout)
{
try
{
new WebDriverWait(driver, timeout).Until(x => false);
}
catch (Exception){}
}
Is there any inherently bad code smell about private extension methods? Which would is better to use? The only issue I see is that if the code is later refactored into a class the methods will have to be rewritten.