private static Expression CreateIndexerAccessExpression(Expression instance, IndexerToken indexerToken)
        {
            var binder = Binder.GetIndex(CSharpBinderFlags.None,
                                         typeof (DynamicPropertyAccessExpressionBuilder),
                                         new[]
                                             {
                                                 CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null),
                                                 CSharpArgumentInfo.Create(
                                                     CSharpArgumentInfoFlags.Constant |
                                                     CSharpArgumentInfoFlags.UseCompileTimeType, null)
                                             });

            return Expression.Dynamic(binder,
                                      typeof (object),
                                      new[]
                                          {
                                              instance,
                                              indexerToken.Arguments
                                                  .Select(Expression.Constant)
                                                  .First()
                                          });
        }
예제 #2
0
 private static MemberInfo GetFromIndexerToken(IndexerToken token, Type type)
 {
     var indexerPropertyInfo = type.GetIndexerPropertyInfo(token.Arguments.Select(a => a.GetType()).ToArray());
     return indexerPropertyInfo != null ? indexerPropertyInfo.GetGetMethod() : null;
 }