The System.CodeDom.Compiler.CodeGenerator class has a private method called GenerateType which takes a type and generates its comments, members, etc.
The thing is, that you can’t really determine the order in which the members will be generated.
This is quite annoying all by itself (you can’t generate pre-processor directives wherever you want them), but acceptable, since there has to be some logic behind the intention of the programmer who wrote this method.
Before I used the Microsoft.CSharp.CSharpCodeGenerator class, which derives from it, I created a CodeDOM graph and wanted to use it.
The collection which holds all the members to be generated is of type System.CodeDom.CodeTypeMemberCollection which has index-specific methods such as Insert, IndexOf and an index-bound CopyTo.
My question is this:
Why create methods that would mislead programmers that don’t want to dive into the code? If the index doesn’t matter, why can I work with it?
And if your answer is “Because you might have other code generators that would want to generate members according to the index”, why isn’t there a single piece of documentation about the fact that indexes don’t matter in the current generators?
Update: I just noticed that I talked about this, but haven’t given the order in which members are written, so here it is:
- Type Comments
- Start of Type Declaration
- Code Snippets
- Type Initializer (Static Constructor)
- Instance Constructors
- Nested Types
- End of Type Declaration