>> 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.