coderushdxcore

How to to get all methods in a class and store in a file Using DXCore?


I am trying to write a simple console application as a learner with Dxcore open Api's. I have parsed a C# file using the following line of code.

   LanguageElement   parsedFile = parser.ParseFile(fileLocation)  

and i want to try few basic things on this file. So i was trying to get all methods in this file and its parameters and place them in a list.

I saw a property which would do this but could not use it.

  DevExpress.CodeRush.StructuralParser.TypeDeclaration.AllMethods

Also few links on Dxcore plugin development documentations would be helpful.

Thanks in Advance.


Solution

  • You can cast your "parserFile" reference to the SourceFile type instance and then use the code like this:

      SourceFile parsedFile = parser.ParseFile(fileLocation) as SourceFile;
      if (parsedFile != null)
        foreach (TypeDeclaration type in parsedFile.AllTypes)
          foreach (Method method in type.AllMethods)
            foreach (Param param in method.Parameters)
            {
              // Do something...
            }
    

    This link may probably be a bit of help: How to enumerate solution and source code items using DXCore