i made this recursive function, but after the "return" it jumps back to the line GetProp(classes, obj); and so it returns twice and I get a wrong value.
Thats how I call the method
foreach (string fieldKey in fieldKeys)
{
Console.WriteLine(fieldKey);
var props = fieldKey.Split('.');
form.SetField(fieldKey, GetProp(props, inv));
}
Here is the method
public static string GetProp(string[] classes, object oldObj)
{
var obj = oldObj.GetType().GetProperty(classes[0]).GetValue(oldObj, null);
if(classes.Length>1)
{
classes = classes.Skip(1).ToArray();
GetProp(classes, obj);
}
return obj.ToString();
}
returnkeyword beforeGetProp(classes, obj);inside yourifstatement.returnline, but you don't do anything with the result from the recursive call not sure what your business logic is, but inside the if shouldn't it bereturn GetProp(classes, obj);? This would prevent the last return from executing