Inheritance: IMemberAccessToken
コード例 #1
0
        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);
        }
        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() });
        }
        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() }));
        }
コード例 #4
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;
        }
コード例 #5
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);
        }
コード例 #6
0
        /// <exception cref="InvalidOperationException"><c>InvalidOperationException</c>.</exception>
        private static MemberInfo GetMemberInfoForType(this IMemberAccessToken token, Type targetType)
        {
            PropertyToken propertyToken = token as PropertyToken;

            if (propertyToken != null)
            {
                return(GetMemberInfoFromPropertyToken(propertyToken, targetType));
            }

            IndexerToken indexerToken = token as IndexerToken;

            if (indexerToken != null)
            {
                return(GetMemberInfoFromIndexerToken(indexerToken, targetType));
            }

            throw new InvalidOperationException(token.GetType().GetTypeName() + " is not supported");
        }
コード例 #7
0
        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;
        }
コード例 #8
0
 private static IEnumerable <Expression> GetIndexerArguments(this IndexerToken indexerToken)
 {
     return(indexerToken.Arguments.Select(a => (Expression)Expression.Constant(a)));
 }