private PropertyInfo QueryPropertyInfoRecursive(Type type, string[] propertyPath, int piece, Action<PropertyInfo> action)
{
string property = propertyPath[piece]; int index;
bool isIndexed = CheckForExistenceAndExtractIndex(ref property, out index);
PropertyInfo propertyInfo = type.GetProperty(property, ResolveFlagsToUse(type));
if (propertyInfo == null)
{
if (logger.IsErrorEnabled)
{
logger.Error("No public property '{0}' found on type '{1}'", property, type.FullName);
}
return null;
}
if (!propertyInfo.CanRead)
{
throw new BindingException("Property '{0}' for type '{1}' can not be read",
propertyInfo.Name, type.FullName);
}
if (propertyInfo.GetIndexParameters().Length != 0)
{
throw new BindingException("Property '{0}' for type '{1}' has indexes, which are not supported",
propertyInfo.Name, type.FullName);
}
if (action != null)
{
action(propertyInfo);
}
type = propertyInfo.PropertyType;
if (typeof(ICollection).IsAssignableFrom(type))
{
return null;
}
if (isIndexed)
{
if (type.IsGenericType)
{
Type[] args = type.GetGenericArguments();
if (args.Length != 1)
throw new BindingException("Expected the generic indexed property '{0}' to be of 1 element", type.Name);
type = args[0];
}
if (type.IsArray)
{
type = type.GetElementType();
}
}
if (piece + 1 == propertyPath.Length)
{
return propertyInfo;
}
return QueryPropertyInfoRecursive(type, propertyPath, piece + 1, action);
}