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() })); }
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 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); }
/// <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"); }
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 static IEnumerable <Expression> GetIndexerArguments(this IndexerToken indexerToken) { return(indexerToken.Arguments.Select(a => (Expression)Expression.Constant(a))); }