'C# Tree of objects filtering based on elements type

I know similar questions have been asked before but mine has some key differences that change it. So lets say I have a class with the following in C#

public class Node
    {
        public string Type { get; set; }

        public Node Parent { get; set; }

        public List<Node> Children { get; set; }
    }

And I have some sort of tree structure with types similar to this:

N1
  - N1
  - N1
N2
  - N3
  - N1
N3
N4
  - N5
      - N1
         -N6
N1
N1
  - N2

How do I filter by Type: N1 so the above tree looks like this:

N1
  - N1
  - N1
N2
  - N1
N4
  - N5
      - N1
N1
N1

Basically I want to filter by Type: N1 but leave the parent nodes if some child node has Type: N1. Im looking for simple C# method(s) that can achieve this, I do not want to add any library or anything. Something like: tree = FilterTree(type, ...)



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source