Skip to content

Commit 596f396

Browse files
committed
Adding option to exclude quoted lambda comment
1 parent 4b5fa88 commit 596f396

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

ReadableExpressions.UnitTests/WhenTranslatingLambdas.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,18 @@ public void ShouldTranslateANestedQuotedLambda()
104104
Assert.AreEqual(EXPECTED.TrimStart(), translated);
105105
}
106106

107+
[TestMethod]
108+
public void ShouldTranslateQuotedLambdaWithNoAnnotation()
109+
{
110+
Expression<Func<int, double>> intToDouble = i => i;
111+
112+
var quotedLambda = Expression.Quote(intToDouble);
113+
114+
var translated = quotedLambda.ToReadableString(o => o.NoQuotedLambdaComments);
115+
116+
Assert.AreEqual("i => (double)i", translated);
117+
}
118+
107119
[TestMethod]
108120
public void ShouldTranslateRuntimeVariables()
109121
{

ReadableExpressions/TranslationSettings.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,20 @@ public TranslationSettings UseExplicitGenericParameters
2525
}
2626

2727
internal bool UseImplicitGenericParameters { get; private set; }
28+
29+
/// <summary>
30+
/// Do not annotate a Quoted Lambda Expression with a comment indicating that it has
31+
/// been Quoted.
32+
/// </summary>
33+
public TranslationSettings NoQuotedLambdaComments
34+
{
35+
get
36+
{
37+
DoNotCommentQuotedLambdas = true;
38+
return this;
39+
}
40+
}
41+
42+
internal bool DoNotCommentQuotedLambdas { get; private set; }
2843
}
2944
}

ReadableExpressions/Translators/QuotedLambdaExpressionTranslator.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ public override string Translate(Expression expression, TranslationContext conte
1414
{
1515
var quote = (UnaryExpression)expression;
1616

17+
if (context.Settings.DoNotCommentQuotedLambdas)
18+
{
19+
return context.TranslateAsCodeBlock(quote.Operand);
20+
}
21+
1722
var comment = ReadableExpression.Comment("Quoted to induce a closure:");
1823
var quotedLambdaBlock = Expression.Block(comment, quote.Operand);
1924

0 commit comments

Comments
 (0)