【发布时间】:2011-04-16 20:57:06
【问题描述】:
我正在使用第 3 方的一组 Web 服务,但遇到了一个小问题。在我手动创建将每个属性从源复制到目标的方法之前,我想我会在这里寻求更好的解决方案。
我有 2 个对象,一个是 Customer.CustomerParty 类型,一个是 Appointment.CustomerParty 类型。 CustomerParty 对象实际上是完全一样的属性和子对象。但我不能从 1 转换到另一个。
所以,我需要从网络服务中找到某个人。我可以通过调用 Customer.FindCustomer(customerID) 来做到这一点,它会返回一个 Customer.CustomerParty 对象。
我需要找到我找到的那个人,然后在“CreateAppointment”请求中使用他们几行。 Appointment.CreateAppointment 接受一个约会对象,该约会对象包含一个 CustomerParty 对象。
但是,它想要的 CustomerParty 对象实际上是 Appointment.CustomerParty。我有一个 Customer.CustomerParty。
明白我的意思了吗?有什么建议吗?
【问题讨论】:
-
因为类来自不同的命名空间,这意味着从 CLR 的角度来看它们完全不同。这就是为什么你不能从另一个中投射一个。
标签: c# namespaces casting