private Expression CreateIndexerAccessExpression(Expression instance, IndexerToken indexerToken)
        {
            CallSiteBinder 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() });
        }
Ejemplo n.º 2
0
        private static bool TryParseIndexerToken(string member, out IndexerToken token)
        {
            token = null;

            if (!IsValidIndexer(member))
            {
                return false;
            }

            List<object> arguments = new List<object>();
            arguments.AddRange(ExtractIndexerArguments(member).Select(a => ConvertIndexerArgument(a)));

            token = new IndexerToken(arguments);

            return true;
        }
        private static MemberInfo GetMemberInfoFromIndexerToken(IndexerToken token, Type targetType)
        {
            PropertyInfo indexerPropertyInfo = targetType.GetIndexerPropertyInfo(token.Arguments.Select(a => a.GetType()).ToArray());
            if (indexerPropertyInfo != null)
            {
                return indexerPropertyInfo.GetGetMethod();
                
            }

            return null;
        }