-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
50 additions
and
0 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
sources/RevitDBExplorer/Extensions/System/Linq.Expressions/MethodCallExpressionExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |