[Solved] Transfer data between objects of same structure but different type


The problem I specified is rather simple. I just wanted to transfer the data from one derived type object to another derived type object of same base since I don’t have access to base class.

Since the object was big, I was required to write a long data transfer logic for the data transfer between them.

So I was looking for a simple solution like a cast(which won’t work in my case).

I have found a roundabout way to transfer data between them. Pasting the code here FWIW

if A.Criteria and B.Criteria are the objects, I wanted data of A to be passed to B. After all the suggestions above. I came up with a round about way.

string json = JsonConvert.SerializeObject(A.Criteria);
return JsonConvert.DeserializeObject(json, typeof(B.Criteria)) as B.Criteria;

solved Transfer data between objects of same structure but different type