I am trying to visualize a C# object which is a SyntaxTree. JSON would be nice, but not required, I am just having a hard time dealing with the VS UI and all the circular references in the object. when I try to use JSON.NET to serialize it, I get a circular reference error. This isn't the first time I have run into a similar problem, but I thought I would work on it for a bit.
I know which keys need to be removed, they are ContainingElement, ContainingNamSpace, ContainingSourceUnit, ContainingType.
I was trying to create a function that could be reused to recursively remove those keys from the object before I pass it to JSON.NET, but I need some help.
public static object removeObjectsByName(object incoming, string WildcardRemove){
List<object newObject = new List<object>();
foreach (var item in incoming)
{
if (subItem.ToString().Contains(WildcardRemove))
{
continue;
}
}
removeObject(newObject);
return newObject;
}
I don't typically do a lot with generic types, but I don't know what all the incoming types of data will be, especially as we call it recursively. Should we create a List
, Array
, or leave it an object
? Here is a sample of what I am looking at:
The root of the object is named tree
, I am specifically interested in the Functions
which has 61 items in the array. As you dig into those you start to find the Containing*
keys that need to be removed. Trouble is that they will also exist under Body
and Properties
. Then under Body
, there is another Properties
which will have it's Containing*
.
I don't need any of that back referencing stuff, I just want each child without any keys named Containing*
.
Any tips? Again, I don't care if the output is JSON, to the Console, as a List, if we use Linq or what, just trying to see my way through this.