@@ -19,7 +19,8 @@ public class Issue300_Bad_label_content_in_ILGenerator_in_the_Mapster_benchmark_
1919 {
2020 public int Run ( )
2121 {
22- Test_301_MemberInit ( ) ;
22+ Test_301_MemberInit_PrivateProperty ( ) ;
23+ Test_301_MemberInit_InternalProperty ( ) ;
2324 Test_301_Invoke_Lambda_inlining_case_simplified ( ) ;
2425 Test_301_Invoke_Lambda_inlining_case ( ) ;
2526 Test_301_Goto_to_label_with_default_value_should_not_return_when_followup_expression_is_present ( ) ;
@@ -29,15 +30,102 @@ public int Run()
2930 Test_301_TryCatch_case ( ) ;
3031 Test_301 ( ) ;
3132 Test_300 ( ) ;
32- return 10 ;
33+ return 11 ;
34+ }
35+
36+ public class CustomerDTO2
37+ {
38+ public int Id { get ; set ; }
39+ public string Name { get ; set ; }
40+ }
41+
42+ public class CustomerWithPrivateProperty
43+ {
44+ public int Id { get ; private set ; }
45+ private string Name { get ; set ; }
46+
47+ private CustomerWithPrivateProperty ( ) { }
48+
49+ public CustomerWithPrivateProperty ( int id , string name )
50+ {
51+ Id = id ;
52+ Name = name ;
53+ }
54+
55+ public bool HasName ( string name )
56+ {
57+ return Name == name ;
58+ }
59+ }
60+
61+ [ Test ]
62+ public void Test_301_MemberInit_PrivateProperty ( )
63+ {
64+ var p = new ParameterExpression [ 2 ] ; // the parameter expressions
65+ var e = new Expression [ 11 ] ; // the unique expressions
66+ var l = new LabelTarget [ 0 ] ; // the labels
67+ var expr = Lambda < System . Func < object , CustomerDTO2 > > ( //$
68+ e [ 0 ] = Block (
69+ typeof ( CustomerDTO2 ) ,
70+ new [ ] {
71+ p [ 0 ] = Parameter ( typeof ( CustomerWithPrivateProperty ) )
72+ } ,
73+ e [ 1 ] = MakeBinary ( ExpressionType . Assign ,
74+ p [ 0 // (CustomerWithPrivateProperty whenmappingprivatefieldsandproperties_customerwithprivateproperty__61071393)
75+ ] ,
76+ e [ 2 ] = Convert (
77+ p [ 1 ] = Parameter ( typeof ( object ) ) ,
78+ typeof ( CustomerWithPrivateProperty ) ) ) ,
79+ e [ 3 ] = Condition (
80+ e [ 4 ] = MakeBinary ( ExpressionType . Equal ,
81+ p [ 0 // (CustomerWithPrivateProperty whenmappingprivatefieldsandproperties_customerwithprivateproperty__61071393)
82+ ] ,
83+ e [ 5 ] = Constant ( null , typeof ( CustomerWithPrivateProperty ) ) ) ,
84+ e [ 6 ] = Constant ( null , typeof ( CustomerDTO2 ) ) ,
85+ e [ 7 ] = MemberInit ( ( NewExpression ) (
86+ e [ 8 ] = New ( // 0 args
87+ typeof ( CustomerDTO2 ) . GetTypeInfo ( ) . DeclaredConstructors . ToArray ( ) [ 0 ] , new Expression [ 0 ] ) ) ,
88+ Bind (
89+ typeof ( CustomerDTO2 ) . GetTypeInfo ( ) . GetDeclaredProperty ( "Id" ) ,
90+ e [ 9 ] = Property (
91+ p [ 0 // (CustomerWithPrivateProperty whenmappingprivatefieldsandproperties_customerwithprivateproperty__61071393)
92+ ] ,
93+ typeof ( CustomerWithPrivateProperty ) . GetTypeInfo ( ) . GetDeclaredProperty ( "Id" ) ) ) ,
94+ Bind (
95+ typeof ( CustomerDTO2 ) . GetTypeInfo ( ) . GetDeclaredProperty ( "Name" ) ,
96+ e [ 10 ] = Property (
97+ p [ 0 // (CustomerWithPrivateProperty whenmappingprivatefieldsandproperties_customerwithprivateproperty__61071393)
98+ ] ,
99+ typeof ( CustomerWithPrivateProperty ) . GetTypeInfo ( ) . GetDeclaredProperty ( "Name" ) ) ) ) ,
100+ typeof ( CustomerDTO2 ) ) ) ,
101+ p [ 1 // (object object__47154838)
102+ ] ) ;
103+
104+ expr . PrintCSharp ( ) ;
105+
106+ var fs = expr . CompileSys ( ) ;
107+ fs . PrintIL ( "sys" ) ;
108+
109+ var customerId = 1 ;
110+ var customerName = "Customer 1" ;
111+ var customer = new CustomerWithPrivateProperty ( customerId , customerName ) ;
112+ var dto1 = fs ( customer ) ;
113+ Assert . AreEqual ( customerName , dto1 . Name ) ;
114+ Assert . AreEqual ( customerId , dto1 . Id ) ;
115+
116+ var ff = expr . CompileFast ( true ) ;
117+ ff . PrintIL ( "fec" ) ;
118+ var dto2 = ff ( customer ) ;
119+ Assert . AreEqual ( customerName , dto2 . Name ) ;
120+ Assert . AreEqual ( customerId , dto2 . Id ) ;
33121 }
34122
35123 [ Test ]
36- public void Test_301_MemberInit ( )
124+ public void Test_301_MemberInit_InternalProperty ( )
37125 {
38126 var p = new ParameterExpression [ 1 ] ; // the parameter expressions
39127 var e = new Expression [ 8 ] ; // the unique expressions
40- var l = new LabelTarget [ 0 ] ; // the labels
128+ var l = new LabelTarget [ 0 ] ; // the labels
41129 var expr = Lambda < System . Func < SimplePoco , SimpleDto > > ( //$
42130 e [ 0 ] = Condition (
43131 e [ 1 ] = MakeBinary ( ExpressionType . Equal ,
0 commit comments