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 / .NET Framework / .NET SDK / March 2006

Tip: Looking for answers? Try searching our database.

CodeDOM query

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Stuart Carnie - 17 Feb 2006 23:34 GMT
In C# 2.0, how does one represent the "yield return" statement using
System.CodeDOM?

Cheers,

Stuart
Nick Hounsome - 18 Feb 2006 12:52 GMT
> In C# 2.0, how does one represent the "yield return" statement using
> System.CodeDOM?
>
> Cheers,
>
> Stuart

You probably can't - there are lots of things that you can't express in
CodeDom as you would normally do in C#. It's not really a design goal to be
able to express every C# and VB construct directly.

yield return is just a compiler convenience thing with no underlying runtime
support - most books I have read provide examples of how the compiler might
implement it in terms of extra hidden classes.

I suppose it would be possible to write a common method to do some of the
grunt work for you.
Stuart Carnie - 20 Feb 2006 07:30 GMT
>> In C# 2.0, how does one represent the "yield return" statement using
>> System.CodeDOM?
[quoted text clipped - 13 lines]
> I suppose it would be possible to write a common method to do some of the
> grunt work for you.

Thanks for the reply, Nick.  I agree - having written a several hundred
lines of code using the CodeDOM namespace, I can see the design goals a
little more clearly now.

It is very convenient, especially as I need to generate both C# and
VB.Net code from my code generator, however it can get quite verbose :)

...all this:

prop.SetStatements.Add(new CodeConditionStatement(
 new CodeBinaryOperatorExpression(
 new CodePropertySetValueReferenceExpression(),
 CodeBinaryOperatorType.IdentityEquality,
 new CodePrimitiveExpression(null)),
 new CodeStatement[] {
  // true statements :
  // this.SetNull(this.ContactIdColumn);
  new CodeExpressionStatement(
   new CodeMethodInvokeExpression(
    new CodeThisReferenceExpression(),
     "SetNull", new CodeExpression[] {
      new CodeFieldReferenceExpression(
       new CodeThisReferenceExpression(), name1)}))},

  // false statements :
  // SetColumnValue(this.ContactIdColumn, value, value.ContactIdColumn);
  new CodeStatement[] {
   new CodeExpressionStatement(
    new CodeMethodInvokeExpression(null,
     "SetColumnValue",
     new CodeExpression[] {
      new CodeFieldReferenceExpression(
       new CodeThisReferenceExpression(), name1),
       new CodePropertySetValueReferenceExpression(),
       new CodeFieldReferenceExpression(
        new CodePropertySetValueReferenceExpression(),
         name2)}))}));

to represent:

set
{
  if ((value == null))
  {
    this.SetNull(this.ContactIdColumn);
  }
  else
  {
    SetColumnValue(this.ContactIdColumn, value, value.ContactIdColumn);
  }
}

It seems like I should create some methods that are short-hand
representations of these long class names (which are fine).

I could then represent it as:

prop.SetStatements.Add(CodeCS(
 CodeBOE(
 CodePSVRE,
 CodeBinaryOperatorType.IdentityEquality,
 CodePE(null)),
 CodeSAr {
  // true statements :
  // this.SetNull(this.ContactIdColumn);
  CodeES(
   CodeMIE(
    CodeThis,
     "SetNull", CodeEAr {
      CodeFRE(
       CodeThis, name1)}))},

  // false statements :
  // SetColumnValue(this.ContactIdColumn, value, value.ContactIdColumn);
  CodeSAr {
   CodeES(
    CodeMIE(null,
     "SetColumnValue",
     CodeEAr {
      CodeFRE(
       CodeThis, name1),
       CodePSVRE,
       CodeFRE(
        CodePSVRE, name2)}))}));

Bad idea?
"Peter Huang" [MSFT] - 20 Feb 2006 08:42 GMT
Hi Stuart,

Thanks for your knowledge sharing in the community.
Also as Nick said, the CodeDom is a general namespace for all the .NET
language, but the yield return is a special keywork recognized by C#
compiler.

Best regards,

Peter Huang
Microsoft Online Partner Support

Signature

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

n4ixt - 23 Mar 2006 20:25 GMT
Just curious on what you used to learn about CodeDOM. Is the online docs
sufficient? Did you get the four volume .net framework manuals? Some other
book / resource?

Thanks,

  Robert

> In C# 2.0, how does one represent the "yield return" statement using
> System.CodeDOM?
>
> Cheers,
>
> Stuart

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.