我在一個應用程序中的類 - 我不能改變(傳統) - 這是一個組件(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獲取值到新列表中?
將LocalizedShippingCost重命名爲LocalShippingCurrency? –