2
I need to write all the primitive properties of a C# object regardless of how many "levels" I enter these objects.
I have the following object in Javascript:
var objeto = {
propriedade:{
valor:42
},
atributo:"foo"
}
So to access all of his properties recursively, I do the following:
function PrintAllProperties(obj){
for(var prop in obj){
if(typeof obj[prop]==="object")
PrintAllProperties(obj[prop]);
else
console.log(obj[prop]);
}
} PrintAllProperties(objeto);
Thus the output is formed by all properties with primitive value no matter the amount of levels that had to be accessed from that "parent object" ( working example )
How to do this in C#?
Note that this will only list public properties.
– dcastro
@dcastro I put with all the
BindingFlags
. I hope I haven’t forgotten anything. Thank you!– Leonel Sanches da Silva