Results 1 to 5 of 5

Thread: Parse(extract) class names and method names from C# code

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2020
    Posts
    1,421

    Parse(extract) class names and method names from C# code

    I need to use VB6 to parse(extract) the class name (including the properties of the class) and the method name (including the method parameters) in the C#. I now have two ideas:

    Method 1: Use a third-party COM-lib or JS-lib to generate AST of C# code, and then parse(extract) out the class name and method name in AST string. I'd like to know what COM libs or JS libs can do this. Thanks.

    Method 2: Parse the C# code character by character, and then extract the class names and method names in the C# code. This method has a certain difficulty, I'd like to know if there are some easy ways or helper tools. Thanks!
    Last edited by SearchingDataOnly; Nov 30th, 2022 at 12:41 AM.

  2. #2

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2020
    Posts
    1,421

    Get the AST (Json String) of C# code

    I want to use VB6 or VB.NET to get the AST (Json String) of C# code, and I know that CodeDom and Roslyn can be used to parse C# code precisely and generate AST node collections and AST json strings. But this approach is too complicated, I really just want to get the class names and method names (including class properties and method parameters) from the C# code. I wonder if there are some smaller COM libs or JS libs or VB helper classes to generate AST strings from C# code? Thank!

  3. #3
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,715

    Re: Get the AST (Json String) of C# code

    If you add the C# class to your VB.NET project, you could use reflection to get those details.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2020
    Posts
    1,421

    Re: Get the AST (Json String) of C# code

    Quote Originally Posted by dday9 View Post
    If you add the C# class to your VB.NET project, you could use reflection to get those details.
    I want to be able to get AST strings without reflection, because eventually I still need to convert these VB.NET algorithms to VB6 code. If reflection is used, the conversion will not work.

    Also, I'm parsing (parsing) C# code, not adding C# Classes to VB.NET project. Or to put it this way, I want to write a lightweight C# parser in VB6.

    My parser doesn't need to be as precise as CodeDom, Roslyn, and ANTL4, it just needs to get some structural information about the C# code.
    Last edited by SearchingDataOnly; Nov 30th, 2022 at 08:44 PM.

  5. #5
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,715

    Re: Parse(extract) class names and method names from C# code

    Moderator Actions: Merged the original VB6 thread with the VB.NET thread.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width