[nem-en] Problem with NemerleCodeGenerator

Andrey Khropov andrey.khropov at gmail.com
Fri Dec 1 00:07:54 CET 2006


Hello,

I'm working on WinForms designer support for VS integration and I need to
generate code for new fields and methods created by designer.

Now the whole <FormName>.Designer.n file is regenerated as a result of user
actions (using NemerleCodeGenerator). But this approach is less than ideal for
main <FormName>.n file when we want to add/remove new methods individually
(because formatting for user code in event handlers should be preserved and not
overwritten by generator).

So better approach is to insert/remove just lines of code that belong to a
particular method (AFAIK designer can only add/remove event handlers in main
file).

The problem is that NemerleCodeGenerator is derived from CodeGenerator that
uses read-only non-virtual property Output for output (awful design decision
IMHO!).
That's why I can't just reuse GenerateField/GenerateMethod  from
NemerleCodeGenerator now :-(.

The problem is even mentioned in VS SDK documents (these folks in MS can't even
make class design good enough to handle use-cases in their own products!!)

So I propose to redefine Output in NemerleCodeGenerator as protected assignable
property (so I could change it when it is needed in my derived class) and to
add code in ICodeGenerator.GenerateCodeFromXXX functions to assign to it like:

protected ICodeGenerator.GenerateCodeFromNamespace(e : CodeNamespace,w :
TextWriter, o: CodeGeneratorOptions) : void
{
	Output = w;
	base.GenerateCodeFromNamespace(e,w,o);
}

Is it okay if I do that?

-- 
AKhropov




More information about the devel-en mailing list