【发布时间】:2013-02-06 17:01:19
【问题描述】:
我在一个应用程序中有一个类 - 我无法更改(旧版) - 它位于程序集(DLL 文件)内部:
public class ShippingMethod
{
public string ShipMethodCode { get; set; }
public string ShipMethodName { get; set; }
public decimal ShippingCost { get; set; }
public List<ShippingMethod> GetAllShippingMethods()
{
......
}
}
我有第二个应用程序正在引用该程序集(DLL 文件),并且需要使用所有运输方法填充下拉列表。例如:“UPS - 3.25 美元”
问题在于它需要为不同的货币使用正确的格式。例如:3.25 美元或 3.25 欧元,具体取决于名为 CountryID 的参数。
我编写了一个函数String DisplayMoney(Decimal Amount, Integer CountryID),它将返回金额的正确格式。
现在我需要将此功能应用于每种运输方式并将其保存到新列表中。 最好的方法是什么?
我可以创建另一个名为 LocalizedShippingMethods 的类,如下所示:
public class LocalizedShippingMethod
{
public ShippingMethod ShipMethod { get; set; }
public string LocalizedShippingCost { get; set; }
}
这是实现这一目标的最佳方式吗?有没有更好的方法使用继承来做到这一点?如果我使用继承,如何将第一个 LIST 中的值获取到 NEW LIST 中?
【问题讨论】:
-
将 LocalizedShippingCost 重命名为 LocalShippingCurrency?
标签: c# class inheritance