private static PropertyInfo GetBestMatchingProperty(string propertyName, Type type) { PropertyInfo[] properties = type.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.FlattenHierarchy); PropertyInfo propertyInfo1 = (PropertyInfo)null; int num = int.MaxValue; for (int index = 0; index < properties.Length; ++index) { PropertyInfo propertyInfo2 = properties[index]; if (propertyInfo2.Name == propertyName) { int distance = PropertyReflector.CalculateDistance(type, propertyInfo2.DeclaringType); if (distance == 0) { return(propertyInfo2); } if (distance > 0 && distance < num) { propertyInfo1 = propertyInfo2; num = distance; } } } return(propertyInfo1); }