ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> DevelopMentor-dotNET
DevelopMentor-dotNET
[DOTNET] Aesthetics Question on the CodeDOM
by Justin Rudd other posts by this author
Nov 24 2001 12:39AM messages near this date
Re: [DOTNET] Programmatically accessing Webform HTML | Re: [DOTNET] Aesthetics Question on the CodeDOM
When people use the code dom, do you find yourself using
CodeSnippetStatement and CodeSnippetExpression a lot or do you try and break
it down into the "correct" statements and expressions?

For example, take the following generated code...
   return "Hello " + name + "!";

You can use...
   CodeSnippetStatement snip = new CodeSnippetStatement(@"return ""Hello ""
+ name + ""!"";");

Or you can use...
   CodeMethodReturnStatement st1 = new CodeMethodReturnStatement();
   CodeBinaryOperatorExpression op1 = new CodeBinaryOperatorExpression();
   CodeBinaryOperatorExpression op2 = new CodeBinaryOperatorExpression();
   op1.Left = new CodePrimitiveExpression("Hello ");
   op1.Operator = CodeBinaryOperatorType.Add;
   op1.Right = op2;
   op2.Left = new CodeArgumentReferenceExpression("name");
   op2.Operator = CodeBinaryOperatorType.Add;
   op2.Right = new CodePrimitiveExpression("!");
   st1.Expression = op1;

Granted the second way is significantly more code, but it makes use of the
DOM and can be traversed without having to parse it by hand later (if that
is needed).

Just curious as to what other people do...

Justin

You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.
Thread:
Justin Rudd
Dan Green
Justin Rudd

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved