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