If I have the following abstract class:
public abstract class Page<T> where T : class
{
public Func<T, object> SortBy { get; private set; }
public Page(Func<T, object> sortBy)
{
this.SortBy = sortBy;
}
}
How can I call the base constructor from the inheriting class? I want to do something like this:
public class ProductGridPage : Page<ProductGrid>
{
public ProductGridPage() : base<ProductGrid>(pg => pg.Title)
{
}
}
However base<ProductGrid>(pg => pg.Title)
is not valid and wont compile.
public abstract class Page<T> where T : class
{
public Func<T, object> SortBy { get; private set; }
public Page(Func<T, object> sortBy)
{
this.SortBy = sortBy;
}
}
public class ProductGridPage : Page<ProductGrid>
{
public ProductGridPage() : base(pg => pg.Title)
{
}
}
public class ProductGrid
{
public string Title;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.