我正在嘗試編寫一個基本的抽象類,其中擴展它的任何類將具有某種類型的List
。如何在抽象類中聲明List變量
上下文是我調用Web服務,並且收到「網頁」的訂單,並且每個訂單有訂單行「頁」等
abstract class Pagination
{
public int _offset { get; set; }
public int _total { get; set; }
public string previous { get; set; }
public string next { get; set; }
// Can I add something here that represents a list of items
// that is overridden in child classes somehow?
// public abstract List<Something?> items { get; set; }
// The purpose is for this generic "getItemCount" function or something similar
/*
public int getItemCount()
{
return items != null ? items.Count() : 0;
}
*/
}
class OrderHeader : Pagination
{
public int orderId { get; set; }
public List<OrderLine> items { get; set; }
}
class OrderLine : Pagination
{
public string sku { get; set; }
public int qty { get; set; }
public List<OrderLineDetails> items { get; set; }
}
class OrderLineDetails
{
public string serialNum { get; set; }
}
看起來你需要讓你的抽象類通用。 – juharr