I'm working on migrating/rewriting some Java generics in C#. I'm getting an error that I don't understand.
(This is partially an experiment based on composition over inheritance to limit bloat for child-classes that don't need some functionality, but it's also just an experiment to better understand C# generics.)
Note: the actual child-class implementations actually work like I expect, it's just the extension method that isn't compiling.
A parent class:
public abstract class PageObject where T : PageObject
{
protected IWebDriver WebDriver => ServiceLocator.GetWebDriver();
public PageObject()
{
PageFactory.InitElements(WebDriver, this);
}
// ... more stuff, but the constructor is the important thing that keeps
// me using an abstract parent class. There are some abstract methods
// that return T so the child classes can return "this" in a fluent api.
}
An interface:
public interface IHasCustomLoadCondition where T : PageObject
{
bool IsLoaded();
}
and an extension method, this is where the error is occuring:
public static T WaitForCustomPageLoad(this T page) where T : IHasCustomLoadCondition
{
wait.Until((d) =>
{
return page.IsLoaded();
});
return page;
}
The error message:
The type 'T' cannot be used as type parameter 'T' in the generic type or method
'IHasCustomLoadCondition'. There is no boxing conversion or type parameter conversion
from 'T' to 'PageObject'.
JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)