This is a silly question, but you can use this code to check if something is a particular type...
if (child is IContainer) { //....
Is ther
This hasn't been mentioned yet. It works and I think it looks better than using !(child is IContainer)
!(child is IContainer)
if (part is IContainer is false) { return; }
https://devblogs.microsoft.com/dotnet/welcome-to-c-9-0/#logical-patterns
if (part is not IContainer) { return; }