I have some trouble about deserializing a message into an undefined object. I call this an undefined object because I don't have any proper class that resemble the data of the message. I only have an interface. Since the project I'm onto is kinda heavy, I won't display every single line of code except if you feel the need to ask.
I have an interface let's call it ITest (That itself implements other interfaces and other class. So it's quite a complex one)
And in my scope, I receive a "message" Serialized with JsonConvert following exactly the pattern of this Interface ITest. I won't go into details how it was actually serialize, but the solution cannot be used for the deserialize aspect. And here comes the problem :
Since I have to deserialize this message into an interface, well... I obviously can't. So I tried many (MANY) workaround that. Using other Nuget (Like "Impromptu Interfaces" or Castle.Core), or even AutoMapping my interface to an Object type (dynamic), but either the code won't compile, or I get only half of the data or I get only the properties with null/0 values. The closest I got to was with Impromptu... I'm kinda desperate right now.
I would like not to make those damn Concrete type. Since I would need a lot of them. DRY concept is bleeding rn :(
Here is Impromptu
var obj = ActLike<ITest>(message)
Here is AutoMapping
public interface ITest
{
string Test { get; set; }
int Val { get; set; }
}
static void Main(string[] args)
{
Mapper.Initialize(cfg => { });
var a = new { Test = "test", Val = 1 };
ITest b = Mapper.Map(a, typeof(Object), typeof(ITest)) as ITest;
}
Where I tried to change that damn "var a" into a dynamic Json object to be used into the mapping. And many other things ...
So yeah ... I'm kinda stuck right now.
Thanks for any help you could give me !