I have a problem where I receive objects from an external api, and deserialized into c# objects in my system. These objects are logged on my system, therefore I need to be able to sanitize them.
A good example of a object structure that I could be dealing with could be this one:
var person = new {
Name = "Filip",
friends = new string[] { "Lorem ipsum @exampel.com för s",
"Ange mailasasa", "Ange mailadress på
formen namn@exampel.com för s",
"Some random text",
"Ange mailadress på formen" },
innerObj = new { s = new List<string>() {
"nge mailadress på formen na.com för s",
"Ange mailadress på formen amn@exampel.com för sökande: 920294-1801",
"Ange mailadress på formen namn@exampel.com fö"},
anotherField = "nldsa",
},
Age = 24
};
Speficially, I need to detect the substring "920294-1801", the regex-part of this problem is not what I want to ask about.
I would like to know the best way to look into a object, look at all it's fields that are string type, also the ones that are nested in other datastructures. In the example here, I need to look into the "InnerObj" and then into the list elements inside that list.
So is there any way that I can receive ALL nested string fields inside a object, and iterate through them?
EDIT: I probably should clarify that I need a approach that can work for object of different internal structure. This means that it should not just work this example object, but many differnt generic objects of differing structure
EDIT: It has been suggested that this question has been asked before, however it has not, since none of the other questions are looking for a general method to get all fields (+ nested fields) from objects of differing structure