简体   繁体   中英

Text Hierarchy Read C#

I am stuck with a seemingly simple problem. I want to read a text hierarchy written somewhat like c# code eg;

Common
{
  MyClass1
  {
    Method1
    {
      "Helloworld";
      "GoodBye";     
    }
    Method2
    {
      "SayGoodMorning";
    }
  }
  MyClass2
  {
    Method3
    {
      "M3";
    }
  }
}

Consider common a namespace which can have many classes, a class may have many methods even a method can have another method (just n level concept). And I wish the result something like:

Common MyClass1 Method1 HelloWorld
Common MyClass1 Method1 GoodBye
Common MyClass1 Method2 SayGoodMorning
Common MyClass2 Method3 M3

This can be n level, any help or guidance will be highly appreciated

Use a Stack object to keep track of the current namespace. Each time you see a "{" push the previous line onto the stack. Each time you see a "}" pop the stack. If the line ends with ";" then use the current values on the stack to build the namespace, then append the current line as the method name.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM