c# - Cast web server object to other (identical) web server object -


I have two web services referenced in my project: one to email service and other tickets The service is called .

Both have a property called email and I now have to do the following in my code:

  var mail = new EmailService.Email () ; Mail .from = "something"; Mail.to = "Someone"; Mail.subject = "Topic"; MailService.Save (mail); TicketService.Send (mail);  

The problem is that expects TicketService.Send () email object TicketService namespace. So it fails at that point.

Casting will also not work in this case:

ticketService.Send (Mailing (Mailing Email));

This gives me the error that it EmailService.Email to TicketService.Email .

I know that I can use something like an automaker and just map it from one object to another but I do not add any dependencies to the solution.

It is not necessary to add something like an automaker, since both email items are identical, then perhaps there is an easy way to do this?

In any way, how can I solve this issue?

Look, if you want to put things in the baggage or you want duck-typing everywhere , Then you are using the wrong language C # is a statically typed language (now it is a little dynamic mixtures) and it will not let you enter any other type of any other type.

Automap is a solution, but a bit more overkill, yes. However, you can do one such thing - prepare a way that will replace one instance of one to another.

Alternatively, if you can refactor code to use the same example of e-mail object, then it will take you less time seriously. But by any means, seriously, just dooo eeet.


Comments