Skip to content

Commit 803883e

Browse files
committed
fixed the lookup for the non-public property setter
1 parent 2737990 commit 803883e

File tree

2 files changed

+55
-2
lines changed

2 files changed

+55
-2
lines changed

src/FastExpressionCompiler/FastExpressionCompiler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5213,7 +5213,7 @@ internal static MethodInfo FindPropertyGetMethod(this Type propHolderType, strin
52135213

52145214
internal static MethodInfo FindPropertySetMethod(this Type propHolderType, string propName)
52155215
{
5216-
var methods = propHolderType.GetMethods();
5216+
var methods = propHolderType.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
52175217
for (var i = 0; i < methods.Length; i++)
52185218
{
52195219
var method = methods[i];

test/FastExpressionCompiler.IssueTests/Issue300_Bad_label_content_in_ILGenerator_in_the_Mapster_benchmark_with_FEC_V3.cs

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public class Issue300_Bad_label_content_in_ILGenerator_in_the_Mapster_benchmark_
1919
{
2020
public int Run()
2121
{
22+
Test_301_MemberInit();
2223
Test_301_Invoke_Lambda_inlining_case_simplified();
2324
Test_301_Invoke_Lambda_inlining_case();
2425
Test_301_Goto_to_label_with_default_value_should_not_return_when_followup_expression_is_present();
@@ -28,7 +29,53 @@ public int Run()
2829
Test_301_TryCatch_case();
2930
Test_301();
3031
Test_300();
31-
return 9;
32+
return 10;
33+
}
34+
35+
[Test]
36+
public void Test_301_MemberInit()
37+
{
38+
var p = new ParameterExpression[1]; // the parameter expressions
39+
var e = new Expression[8]; // the unique expressions
40+
var l = new LabelTarget[0]; // the labels
41+
var expr = Lambda<System.Func<SimplePoco, SimpleDto>>( //$
42+
e[0]=Condition(
43+
e[1]=MakeBinary(ExpressionType.Equal,
44+
p[0]=Parameter(typeof(SimplePoco)),
45+
e[2]=Constant(null, typeof(SimplePoco))),
46+
e[3]=Constant(null, typeof(SimpleDto)),
47+
e[4]=MemberInit((NewExpression)(
48+
e[5]=New( // 0 args
49+
typeof(SimpleDto).GetTypeInfo().DeclaredConstructors.ToArray()[0], new Expression[0])),
50+
Bind(
51+
typeof(SimpleDto).GetTypeInfo().GetDeclaredProperty("Id"),
52+
e[6]=Property(
53+
p[0 // (SimplePoco whenexplicitmappingrequired_simplepoco__63821092)
54+
],
55+
typeof(SimplePoco).GetTypeInfo().GetDeclaredProperty("Id"))),
56+
Bind(
57+
typeof(SimpleDto).GetTypeInfo().GetDeclaredProperty("Name"),
58+
e[7]=Property(
59+
p[0 // (SimplePoco whenexplicitmappingrequired_simplepoco__63821092)
60+
],
61+
typeof(SimplePoco).GetTypeInfo().GetDeclaredProperty("Name")))),
62+
typeof(SimpleDto)),
63+
p[0 // (SimplePoco whenexplicitmappingrequired_simplepoco__63821092)
64+
]);
65+
66+
expr.PrintCSharp();
67+
68+
var fs = expr.CompileSys();
69+
fs.PrintIL("sys");
70+
71+
var poco = new SimplePoco {Id = Guid.NewGuid(), Name = "TestName"};
72+
var dto1 = fs(poco);
73+
Assert.AreEqual(poco.Name, dto1.Name);
74+
75+
var ff = expr.CompileFast(true);
76+
ff.PrintIL("fec");
77+
var dto2 = ff(poco);
78+
Assert.AreEqual(poco.Name, dto2.Name);
3279
}
3380

3481
[Test]
@@ -542,6 +589,12 @@ public class SimplePoco
542589
public string Name { get; set; }
543590
}
544591

592+
public class SimpleDto
593+
{
594+
public Guid Id { get; set; }
595+
public string Name { get; internal set; }
596+
}
597+
545598
[Test]
546599
public void Test_301_TryCatch_case()
547600
{

0 commit comments

Comments
 (0)