I have two similar[all attributes are same.] structures within different namespaces.
Now when i try to copy values between the objects of these structures i am getting errors.
How can i make it possible to copy values between objects of two similar structures residing in different namespaces?
Thanks in advance.
Regards,
John
You can't, automatically, just using the framework's built-in conversions.
The short names (i.e. within the namespace) are entirely irrelevant here - as far as the CLR is concerned, A.B.C.SomeType and A.B.C1.SomeType are as different as X.Y.Foo and A.B.Bar.
You should either write your own conversion routines, or (preferrably) avoid having two different types in the first place, if they do the same thing. Alternatively you could use a reflection-based approach to perform the conversion... but that's still not getting the runtime to do it.
Use AutoMapper.
Mapper.CreateMap<My.NS1.Structure, My.NS2.Structure>();
My.NS1.Structure struct1;
My.NS2.Structure struct2 = (My.NS2.Structure) Mapper.Map(struct1);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With