Dear Leif,
I have been trying to do the same as you are doing. I have found that the only way of getting a standalone form designer, is by using the DesignSurface class (with a CodeDomDesignLoader). However, it indeed needs a parser to work with. There are a couple of parsers (NRefactory, Visual Studio, CodeRush and ActiPro's). I haven't been able to get a working instance of the Visual Studio and CodeRush ones, as these are integrated in the VS IDE. NRefactory works, but it is very primitive and you'll need to adhere to their member resolving classes. So I tried ActiPro...
While using the AstVisitor, you can visit every astnode in the tree. First, you will need to catch the CodeTypeDeclarations:
- ClassDeclaration (the class of the current file)
- MethodDeclaration (the InitializeComponents method)
- FieldDeclaration (the components etc)
Add those to your variable CodeTypeDeclarations.
Then... visit all expressions and add them to a codestack (codeStack As New Collections.Generic.Stack(Of Object)), while poping and pushing (accordingly to the current level you are visiting. This will result in correct parenting).
Now add that stack to the method, your class to a namespace, and your done!
Currently the sourcecode is outputting correctly (so, almost done!), but there is one problem: ActiPro only visits MemberAccess, while the CodeDom separates them in Field/Property/Method. So, while visiting the MemberAccess node, I need to determine whether the member is a field, property or a method. Currently, I haven't found a way to do this. I asked ActiPro... they replied with:
Quote:
That's a bit tricky. IDomMember is the interface for member declarations.
MemberAccess is not a member declaration, rather it is the calling of a member declaration for execution. So you must resolve the Expression into a type and then search for a member on that with the MemberName. Your best bet if possible is to get a context at the offset at which the member name ends since that should execute the very complicated code that we have to try and convert an expression into a reference.
To be honest, I still don't know how to implement the code. Do you perhaps know how to do this?
Greetings,
Michel