Reputation: 10248
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.
Upvotes: 0
Views: 836
Reputation: 16981
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;
}
Upvotes: 3