如何更改类的构造函数以接收已创建类和构造函数的通用对象列表?(C#)

我有以下课程:


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?


慕村9548890
浏览 150回答 2
2回答
打开App,查看更多内容
随时随地看视频慕课网APP