0

I have been stuck with this for couple of days. Basically what I am trying to do is assign the values to the property in the ViewModel from the BaseViewModel.

In my BaseViewModel I have the following code:

 var abc1 = this.GetType();
 var method = 
typeof(JsonConvert).GetTypeInfo().GetDeclaredMethods("DeserializeObject")
 .FirstOrDefault(m => m.IsGenericMethod == true && m.GetParameters().Count() == 1);
 MethodInfo generic = method.MakeGenericMethod(abc1);
 var pageData = generic.Invoke(null, new[] { pageState.PageData });

Where var PageData, is the type of the current viewmodel that is active. When this line gets executed, I can see that the setters of all my properties in ViewModel gets called too, and I see the right value in it. But as soon as the execution moves the next line, the values set to default ones, and my binding does not work.

I am using the above code in a Xamarin forms project. I have made a post earlier , but I guess I did not explain the issue correctly.

Libin Joseph
  • 7,070
  • 5
  • 29
  • 52
  • Could you provide more details on how this method is called and an example of a `ViewModel` that derives from the `BaseViewModel`? – Micah Switzer Jun 14 '18 at 17:51
  • 1
    @MicahSwitzer : thanks for yopur repsonse. I have managed to fix the issue. My deserialization code was correct, the viewmodel was overriding certain values. Thanks once again – Libin Joseph Jun 18 '18 at 00:59
  • Awesome! I'm glad you figured it out! – Micah Switzer Jun 18 '18 at 01:00
  • @MicahSwitzer : I have one another question, if its something you can help, it will be awesome : https://stackoverflow.com/questions/50901621/deserialising-json-using-reflection-which-has-nested-json – Libin Joseph Jun 18 '18 at 01:07

0 Answers0