Skip to content

Commit

Permalink
ups
Browse files Browse the repository at this point in the history
  • Loading branch information
NeVeSpl committed May 17, 2024
1 parent 7707bbe commit 500e418
Showing 1 changed file with 50 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using System.Collections.Generic;
using System.Reflection;
using Autodesk.Revit.DB;
using ExpressionTreeToString;

// (c) Revit Database Explorer https://github.com/NeVeSpl/RevitDBExplorer/blob/main/license.md

namespace System.Linq.Expressions
{
internal static class MethodCallExpressionExtensions
{
public static string ToCeSharp(this MethodCallExpression methodCallExpression)
{
string syntax = null;
if (methodCallExpression.Object is ParameterExpression)
{
var uniformMethodCallExpression = methodCallExpression.Update(Expression.Parameter(methodCallExpression.Object.Type, "item"), methodCallExpression.Arguments);
syntax = uniformMethodCallExpression.ToString("C#");
}
if (methodCallExpression.Object == null)
{
var arguments = new List<Expression>();
foreach (var arg in methodCallExpression.Arguments)
{
if (arg is ParameterExpression)
{
var isDocument = arg.Type == typeof(Document);
arguments.Add(Expression.Parameter(arg.Type, isDocument ? "document" : "item"));
continue;

}
if (arg is MemberExpression member)
{
var isDocument = member.Expression.Type == typeof(Document);
arguments.Add(Expression.Property(Expression.Parameter(member.Expression.Type, isDocument ? "document" : "item"), member.Member as PropertyInfo));
continue;
}
arguments.Add(arg);
}



var uniformMethodCallExpression = methodCallExpression.Update(null, arguments);
//var syntaxb = methodCallExpression.ToString("C#");
syntax = uniformMethodCallExpression.ToString("C#");
}
return syntax;
}
}
}

0 comments on commit 500e418

Please sign in to comment.