-3

I have two dlls that are dllA and dllB.

I have same object in both the dlls mentioned as below.

class OrderObect 
{ 
    public string firstName {get;set;} 
    public string lastName {get;set;}
}

I am sending the List from dllA to dllB.

I am getting one exception that is Cannot convert list of dllA.OrderObject to list of dllB.OrderObject.

So how to solve that, Thank you :)

pankaj
  • 207
  • 6
  • 18
  • If B references A and OrderObect is exposed simply remove OrderObect from B & use A.OrderObect. If you want it in both then put it or an interface in a 3rd assembly and have A & B reference that. – Alex K. Jan 13 '17 at 15:18

2 Answers2

-1

Why duplicating those classes? Whatever, if properties name are the same, you could use reflection and loop through properties to copy values from one to other. Look to this post to know how to achieve this : here

Community
  • 1
  • 1
Creep
  • 300
  • 3
  • 12
  • Using reflection for known types doesn't make sense. – Clemens Jan 13 '17 at 15:33
  • As they are in two different assemblies (maybe "moving" assemblies) with classes which are the same today but maybe not totally tomorrow (the concept of duplicating the same class make no sense for me but anyway...), I don't know how to achieve this differently, any idea ? – Creep Jan 13 '17 at 15:36
  • 2
    `sourceList.Select(o => new B.OrderObject { ... } ).ToList();` – Clemens Jan 13 '17 at 15:38
-1

As Creep says if the properties are the same in both then you can use reflection. A slightly easier way if to use something like express mapper to do the mapping for you

Kevin Ross
  • 7,185
  • 2
  • 21
  • 27
  • Any reason for the down vote? My answer will do what the OP wanted and offers one way around their problem. – Kevin Ross Jan 16 '17 at 08:30