ReadableExpressions icon indicating copy to clipboard operation
ReadableExpressions copied to clipboard

Translation of LambdaExpression type "Action" that executes IF statement

Open nquandt opened this issue 3 years ago • 1 comments

Hi, I'm utilizing this library for some Metaprogramming and am having issues with the rendering of typeof(Action) lambdas. I was wondering if you could submit a fix for the following. I've included a very simplified example... in my actual code the body of the if statement is much longer.

using System;
using System.Linq;
using System.Linq.Expressions;
using AgileObjects.ReadableExpressions;

public class Program
{
	public static void Main()
	{
		var x = Expression.IfThen(Expression.Constant(true), Expression.Empty());
		var lamb = Expression.Lambda(x, "someLambda", Enumerable.Empty<ParameterExpression>());
		var func = Expression.Variable(lamb.Type, lamb.Name);
		var assign = Expression.Assign(func, lamb);
		var totalBlock = Expression.Block(new ParameterExpression[]{func}, assign);
		Console.WriteLine(totalBlock.ToReadableString(x =>
		{
			return x.ShowLambdaParameterTypes;
		}));
	}
}

output is

Action someLambda = () => if (true)
{
};

expected

Action someLambda = () =>
{
    if (true)
    {
    }
};

nquandt avatar Aug 19 '22 20:08 nquandt

Hi,

Thanks for letting me know about this - I'll look at the issue and your PR soon.

All the best,

Steve

SteveWilkes avatar Aug 21 '22 08:08 SteveWilkes

With apologies for the long delay, this is fixed as of v4.

SteveWilkes avatar Jan 06 '23 11:01 SteveWilkes