Tarun Rajak

Tarun Rajak

  • 1.3k
  • 461
  • 341.7k

How to do recursive call of a generic T return type method?

Apr 9 2018 8:59 AM
public static T Deserialize(string json) where T : class, new()   {       //Some logic       var obj = default(T);       foreach (var ss in splitdata)       {           var sp2 = ss.Split(':');           if (obj.GetType().GetProperty(sp2[0]).PropertyType == typeof(bool))           {               obj.GetType().GetProperty(sp2[0]).SetValue(obj, bool.Parse(sp2[1]));           }           else if (obj.GetType().GetProperty(sp2[0]).PropertyType == typeof(double))           {               obj.GetType().GetProperty(sp2[0]).SetValue(obj, double.Parse(sp2[1]));           }           else if (obj.GetType().GetProperty(sp2[0]).PropertyType == typeof(object))           {               /// Here i want to do recursive call. How can i do that?               /// var innerobj = Deserialize< ????? >(sp2[1]);               obj.GetType().GetProperty(sp2[0]).SetValue(obj, innerobj);         }       }         return obj;   } *What to write in place of ???? in code?

Answers (1)