Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/308.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 我们可以从客户端添加泛型类的新功能吗?_C#_.net_Class_Generics - Fatal编程技术网

C# 我们可以从客户端添加泛型类的新功能吗?

C# 我们可以从客户端添加泛型类的新功能吗?,c#,.net,class,generics,C#,.net,Class,Generics,假设我有一个产品的泛型类 public class Product { public int ProductID { get; set; } public string ProductName { get; set; } public string Category { get; set; } public decimal UnitPrice { get; set; } public int UnitsInStock { get; set; } } 在客

假设我有一个产品的泛型类

public class Product
{
    public int ProductID { get; set; }
    public string ProductName { get; set; }
    public string Category { get; set; }
    public decimal UnitPrice { get; set; }
    public int UnitsInStock { get; set; }
}
在客户端代码中

 List<Product> prdList = new List<Product>();
List prdList=new List();

我的问题是,是否可以在不影响实际通用产品类的情况下,从客户端添加通用列表集合的新功能?只是子类
产品

public class OurProduct : Product
{
    public string ProductSKU { get; set; }
}
并按如下方式使用:

List<OurProduct> prdList = new List<OurProduct>();
List prdList=new List();

您可能想看看“Decorator”设计模式。它可以帮助您添加新功能,而不必修改原始类。您指的是什么类型的功能?如果我想在客户端代码中添加ProductSKU。您的
产品
类甚至不是泛型的,您所说的
客户端代码
是什么意思?产品类是库。客户机代码只是用户使用此产品类的位置。