3

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.

Sachin
  • 155
  • 1
  • 8

2 Answers2

4

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

Alex Skorkin
  • 4,264
  • 3
  • 25
  • 47
2

I believe you're looking for the following code.

SourceFile parsedFile = CodeRush.Language.Parse(fileName);
foreach (TypeDeclaration type in parsedFile.AllTypes)
{
    foreach (Method method in type.AllMethods)
    {
        // do stuff
    }
}

Note the change from LanguageElement to SourceFile.

Rory Becker
  • 15,551
  • 16
  • 69
  • 94
  • Thank you Rory, SourceFile parsedFile = parser.ParseFile(filelocation) as SourceFile; worked as i had used CSharp30Parser parser = new CSharp30Parser();. I dont know the namespace I have to import for CodeRush in SourceFile parsedFile = CodeRush.Language.Parse(fileName);. – Sachin Apr 14 '11 at 13:01