Skip to content

Commit b612372

Browse files
committed
revert last change
1 parent da49c96 commit b612372

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

ExTree/ExTree.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<PropertyGroup>
44
<TargetFramework>netstandard2.0</TargetFramework>
55
<AssemblyName>Streamx.Linq.ExTree</AssemblyName>
6-
<VersionPrefix>3.1.9</VersionPrefix>
6+
<VersionPrefix>3.1.10</VersionPrefix>
77
<!--<VersionSuffix>preview</VersionSuffix>-->
88
</PropertyGroup>
99

ExTree/ExpressionTree.cs

+15-5
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,13 @@ public static Expression<TDelegate> Parse<TDelegate>(object target, MethodInfo m
2525
}
2626

2727
private readonly struct CacheEntry {
28-
public readonly Expression Body;
28+
public readonly Expression Body;
29+
public readonly Expression Target;
2930
public readonly IList<ParameterExpression> Parameters;
3031

31-
public CacheEntry(Expression body, IList<ParameterExpression> parameters) {
32-
Body = body;
32+
public CacheEntry(Expression body, Expression target, IList<ParameterExpression> parameters) {
33+
Body = body;
34+
Target = target;
3335
Parameters = parameters;
3436
}
3537
}
@@ -121,6 +123,12 @@ public static LambdaExpression Parse(Type delegateType, Expression targetExpress
121123

122124
{
123125
var map = new Dictionary<Expression, Expression>();
126+
var target = targetExpression;
127+
if (target != null) {
128+
target = Expression.Constant(targetExpression.Type.IsValueType ? Activator.CreateInstance(targetExpression.Type) : null,
129+
targetExpression.Type);
130+
map.Add(targetExpression, target);
131+
}
124132

125133
if (arguments != null) {
126134
for (var i = 0; i < arguments.Count; i++) {
@@ -133,7 +141,7 @@ public static LambdaExpression Parse(Type delegateType, Expression targetExpress
133141
lock (CACHE) {
134142
if (!CACHE.TryGetValue(cacheKey, out cached)) {
135143

136-
cached = new CacheEntry(body, parameters);
144+
cached = new CacheEntry(body, target, parameters);
137145
CACHE.Add(cacheKey, cached);
138146
}
139147
}
@@ -143,8 +151,10 @@ public static LambdaExpression Parse(Type delegateType, Expression targetExpress
143151

144152
Expression bind(CacheEntry entry) {
145153
Expression cachedBody = entry.Body;
146-
if (parameters.Any()) {
154+
if (entry.Target != null || parameters.Any()) {
147155
var map = new Dictionary<Expression, Expression>();
156+
if (entry.Target != null)
157+
map.Add(entry.Target, targetExpression);
148158

149159
for (var i = 0; i < entry.Parameters.Count; i++) {
150160
var arg = arguments?[i];

0 commit comments

Comments
 (0)