所以我很遗憾如何将数据添加到字典后将数据发送回对象。
使用此数据结构,我为完整代码<{p}} http://pastebin.com/HicZMzAt
我有
public class Computer
{
public Computer() { }
public Computer(int _year)
{
dropOffDate = DateTime.Now;
RepairFinished = false;
Year = _year;
}
private DateTime dropOffDate;
public bool RepairFinished;
private readonly int Year;
public static string Plate;
private string make;
public string Make
{
get { return make; }
set { make = value; }
}
public string Model { get; set; }
public string ComputerTicketId { get; set; }
public bool IsLaptop { get; set; }
public Location Location { get; set; }
public int HoursWorked { get; set; }
public double PartsCost { get; set; }
public DateTime DateFinished { get; set; }
// public virtual double TotalCost { get { TotalCost = (this.HoursWorked * 50) + PartsCost; } set; }
public void ComputerPickUp()
{
Console.WriteLine("Cost is {0:C} ", this.HoursWorked);
RepairFinished = true;
}
我想计算每次丢弃系统的不同修理费用。
public class Laptop : Computer
{
public bool HasCharger { get; set; }
public Laptop(int year, bool _HasCharger)
: base(year)
{
HasCharger = _HasCharger;
}
//TODO overide for COST ! + 10
我有一个桌面类,桌面系统的维修成本也更便宜。
但我正在使用
public static class Repair
{
public static Dictionary<string, object> RepairLog { get; set; }
}
跟踪维修 现在我迷失在程序的UI部分,以获取数据来确定定价。
public class RepairUI
{
....edited
Repair.RepairLog = new Dictionary<string, object>();
....
Computer = new Desktop(ComputerYear, HasLcd);
这就是我对处理数据的方式感到迷茫,每个修复单元(桌面/ NBK)的类数据都是在字典中组织的,现在我想获取数据并编辑修复成本。对象,但我似乎无法弄清楚如何到达对象。
那么我怎么能问起工作时间和计算单位的信息?
答案 0 :(得分:2)
这听起来像是使用界面的好时刻!
public Interface IRepairable
{
double GetRepairCost();
}
然后重新定义计算机
public class Computer : IRepairable
{
public double GetRepairCost()
{
return (this.HoursWorked * 50) + PartsCost;
}
}
和笔记本电脑
public class Laptop : Computer
{
public new double GetRepairCost()
{
return base.GetRepairCost() + 10;
}
}
和修复
public static class Repair
{
public static Dictionary<string, IRepairable> RepairLog { get; set; }
}
现在你有了一个可以调用GetRepairCost()的词典!这些可能是计算机或笔记本电脑或混合,它对RepairLog来说并不重要!