Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / Design Time / August 2006

Tip: Looking for answers? Try searching our database.

CodeDomDesignerLoader regenerating code for members from base form

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
j@thewolfweb.com - 15 Aug 2006 17:29 GMT
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
j@thewolfweb.com - 15 Aug 2006 21:43 GMT
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?

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.