88
99namespace DynamicExpresso . Resolution
1010{
11- internal class LateGetMemberCallSiteBinder : CallSiteBinder
11+ internal interface IConvertibleToWritableBinder
12+ {
13+ CallSiteBinder ToWritableBinder ( ) ;
14+ }
15+
16+ internal class LateGetMemberCallSiteBinder : CallSiteBinder , IConvertibleToWritableBinder
1217 {
1318 private readonly string _propertyOrFieldName ;
1419
@@ -19,11 +24,39 @@ public LateGetMemberCallSiteBinder(string propertyOrFieldName)
1924
2025 public override Expression Bind ( object [ ] args , ReadOnlyCollection < ParameterExpression > parameters , LabelTarget returnLabel )
2126 {
27+ // there's only one argument: the instance on which the member is accessed
2228 var binder = Binder . GetMember (
2329 CSharpBinderFlags . None ,
2430 _propertyOrFieldName ,
2531 TypeUtils . RemoveArrayType ( args [ 0 ] ? . GetType ( ) ) ,
26- new [ ] { CSharpArgumentInfo . Create ( CSharpArgumentInfoFlags . None , null ) }
32+ parameters . Select ( x => CSharpArgumentInfo . Create ( CSharpArgumentInfoFlags . None , null ) )
33+ ) ;
34+ return binder . Bind ( args , parameters , returnLabel ) ;
35+ }
36+
37+ public CallSiteBinder ToWritableBinder ( )
38+ {
39+ return new LateSetMemberCallSiteBinder ( _propertyOrFieldName ) ;
40+ }
41+ }
42+
43+ internal class LateSetMemberCallSiteBinder : CallSiteBinder
44+ {
45+ private readonly string _propertyOrFieldName ;
46+
47+ public LateSetMemberCallSiteBinder ( string propertyOrFieldName )
48+ {
49+ _propertyOrFieldName = propertyOrFieldName ;
50+ }
51+
52+ public override Expression Bind ( object [ ] args , ReadOnlyCollection < ParameterExpression > parameters , LabelTarget returnLabel )
53+ {
54+ // there are two arguments: the instance on which the member is set and the value to set
55+ var binder = Binder . SetMember (
56+ CSharpBinderFlags . None ,
57+ _propertyOrFieldName ,
58+ TypeUtils . RemoveArrayType ( args [ 0 ] ? . GetType ( ) ) ,
59+ parameters . Select ( x => CSharpArgumentInfo . Create ( CSharpArgumentInfoFlags . None , null ) )
2760 ) ;
2861 return binder . Bind ( args , parameters , returnLabel ) ;
2962 }
@@ -96,16 +129,36 @@ public override Expression Bind(object[] args, ReadOnlyCollection<ParameterExpre
96129 /// <summary>
97130 /// Binds to an items invocation of an instance as late as possible. This allows the use of anonymous types on dynamic values.
98131 /// </summary>
99- internal class LateInvokeIndexCallSiteBinder : CallSiteBinder
132+ internal class LateGetIndexCallSiteBinder : CallSiteBinder , IConvertibleToWritableBinder
100133 {
101134 public override Expression Bind ( object [ ] args , ReadOnlyCollection < ParameterExpression > parameters , LabelTarget returnLabel )
102135 {
136+ // there are two arguments: the instance on which the member is set and the value of the indexer
103137 var binder = Binder . GetIndex (
104138 CSharpBinderFlags . None ,
105139 TypeUtils . RemoveArrayType ( args [ 0 ] ? . GetType ( ) ) ,
106140 parameters . Select ( x => CSharpArgumentInfo . Create ( CSharpArgumentInfoFlags . None , null ) )
107141 ) ;
108142 return binder . Bind ( args , parameters , returnLabel ) ;
109143 }
144+
145+ public CallSiteBinder ToWritableBinder ( )
146+ {
147+ return new LateSetIndexCallSiteBinder ( ) ;
148+ }
149+ }
150+
151+ internal class LateSetIndexCallSiteBinder : CallSiteBinder
152+ {
153+ public override Expression Bind ( object [ ] args , ReadOnlyCollection < ParameterExpression > parameters , LabelTarget returnLabel )
154+ {
155+ // there are three arguments: the instance on which the member is set, the value of the indexer, and the value to set
156+ var binder = Binder . SetIndex (
157+ CSharpBinderFlags . None ,
158+ TypeUtils . RemoveArrayType ( args [ 0 ] ? . GetType ( ) ) ,
159+ parameters . Select ( x => CSharpArgumentInfo . Create ( CSharpArgumentInfoFlags . None , null ) )
160+ ) ;
161+ return binder . Bind ( args , parameters , returnLabel ) ;
162+ }
110163 }
111164}
0 commit comments