我有以下课程:public class OrderArticlesAdapter : RecyclerView.Adapter{ public List<OrderArticleViewModel> listOfOrderArticles; ..... ..... //constructor public OrderArticlesAdapter(List<OrderArticleViewModel> orderArticles, ....., .....) { listOfOrderArticles = orderArticles; ...... }}我希望该类不仅能够处理列表,OrderArticleViewModel还能够处理类型列表Invoices和任何其他类型。OrderArticleViewModel类看起来像这样:public class OrderArticleViewModel{ public string ArticleId { get; set; } public string LotId { get; set; } public string ArticleName { get; set; } public string PriceDiscount { get; set; } public string ArticlePrice { get; set; } public string ArticleQuantity { get; set; } public string ArticleTotalPrice { get; set; } public string Barcode { get; set; } public string ExpireDate { get; set; } public string LotName { get; set; } public string ArticlePriceAfterDiscount { get { decimal priceDiscount; if (!Decimal.TryParse(PriceDiscount, out priceDiscount)) { priceDiscount = 0; } decimal articlePrice = Convert.ToDecimal(ArticlePrice); decimal discountAmount = Math.Round(articlePrice * (priceDiscount / 100), 4); decimal articlePriceAfterDiscount = articlePrice - discountAmount; return articlePriceAfterDiscount.ToString(); } }}ArticleId, ArticleName, ArticleQuantity, PriceDiscount, ArticlePrice, Discount, ArticlePriceAfterDiscountfrom classOrderArticleViewModel对应于属性ArtId, Name, Quantity, Discount, Price, Sumfrom class Invoices。如何使OrderArticlesAdapter构造函数能够接收OrderArticleViewModel或Invoices或任何其他类型的通用列表,而不会破坏我已经使用过实例的代码的功能OrderArticlesAdapter?
2 回答
- 2 回答
- 0 关注
- 149 浏览
添加回答
举报
0/150
提交
取消