all groups > dotnet windows forms designtime > august 2006 >
You're in the

dotnet windows forms designtime

group:

CodeDomDesignerLoader regenerating code for members from base form



CodeDomDesignerLoader regenerating code for members from base form j NO[at]SPAM thewolfweb.com
8/15/2006 9:29:49 AM
dotnet windows forms designtime: I've derived from CodeDomDesignerLoader in order to generate VB code
for forms that I've designed in a custom designer. My current
implementation of Parse is essentially just the following, which
creates a shell form with a base type specified:

codeCompileUnit = new CodeCompileUnit();

codeCompileUnit.ReferencedAssemblies.Add(this.baseType.Assembly.Location);
this.typeResolutionService.ReferenceAssembly(this.baseType.Assembly.GetName());

CodeNamespace codeNamespace = new
CodeNamespace("Elsinore.CustomForms");
codeCompileUnit.Namespaces.Add(codeNamespace);

CodeTypeDeclaration codeType = new
CodeTypeDeclaration(this.baseType.Name + "Ex");
codeType.BaseTypes.Add(new CodeTypeReference(this.baseType));
codeNamespace.Types.Add(codeType);

// constructor will be made private if not explicitly added
CodeConstructor codeConstructor = new CodeConstructor();
codeConstructor.Attributes = MemberAttributes.Public;
codeType.Members.Add(codeConstructor);

My implementation of Write looks like the following:

StringWriter stringWriter = new StringWriter();
this.codeProvider.GenerateCodeFromCompileUnit(unit, stringWriter,
null);
this.sourceCode = stringWriter.ToString();

This works to some extent. The problem is that the CodeCompileUnit
passed into Write has ALL members of the form declared, including those
that were already declared on the base form. I've looked at creating
my own TypeCodeDomSerializer for the form to do the filtering of
statements, but I can't help but think that this filtering is already
built into the framework somehow. So, how do I get the
CodeDomDesignerLoader to only generate declarations and statements for
the derived form?

Thanks in advance!
Jake
Re: CodeDomDesignerLoader regenerating code for members from base form j NO[at]SPAM thewolfweb.com
8/15/2006 1:43:01 PM
I solved this by using the DesignSurface component now included in .NET
2.0. It must provide an extra service that I wasn't before.

Now I get a problem loading a form that references controls declared
"protected" in a base form. The exception says for example: The type
'X' has no property named 'Y'.

I figure here I need to create a new TypeDecriptor for it?
AddThis Social Bookmark Button