c# - 减少成员类中列表属性的数量

标签 c# templating

我正在为特定的内部文件开发模板引擎。我目前有这段代码:

 public class properties
    {
        [DefaultValue("")]
        public string CompanyName { get; set;}
        [DefaultValue("")]
        public string Address { get; set; }
        [DefaultValue("")]
        public string AddressExtra { get; set; }
        [DefaultValue("")]
        public string InvoiceNumber { get; set; }
        [DefaultValue("")]
        public string InvoiceDate { get; set; }
        [DefaultValue("")]
        public string OrderNumber { get; set; }
        [DefaultValue("")]
        public string Rep { get; set; }
        [DefaultValue("")]
        public string Status { get; set; }
        [DefaultValue("")]
        public string TaxRate { get; set; }
        [DefaultValue("")]
        public string Quantity1 { get; set; }
        public string Quantity2 { get; set; }
        ...
    }

与此模板一致:Template 作为 C# 开发区的“新手”。我想知道是否可以重新定义成员类中大量重复属性的实现逻辑。即:

Quantity1、Quantity2、Quantity3、Quantity4 ...一直到 14,与所有其他重复区域相同。

不知道如何重新考虑这个逻辑,我转向 Stackoverflow 寻求可能的想法(不是外部库。我希望这是一个学习曲线并且自包含)。

最佳答案

很明显,您应该有一个“LineItem”类,例如:

public class LineItem
{
   public int Quantity {get; set;}
   public string Product {get; set;}
   public double UnitPrice {get; set;}
   public double TotalAmount {get; set;}
}

您的“订单”类(您称它为“属性”,不是类的好名称)然后将包含这些的集合。

即。

public class Order
{
   public string CompanyName {get; set;}
   ...
   public List<LineItem> Items {get; set;}
}

关于c# - 减少成员类中列表属性的数量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25776871/

相关文章:

c# - 将 ASP.NET Identity 用户链接到用户详细信息表

c# - Entity Framework 批量插入抛出 KeyNotFoundException 错误

c# - 使用 C# 调用 RESTful API

c# - 将字节数组复制到 C# 中的另一个字节数组

Xamarin.Forms - "include"是否有局部 View 的机制?

php - 模板引擎+前端框架

php - 什么是模板语言?

java - Thymeleaf 模板 :data=http://www. somesite.com || org.thymeleaf.exceptions.TemplateProcessingException:无法解析为分配序列

c# - 如何在列表框中显示替代对象的表示?

php - PHP 中的模板制作正确...如何?