FindMostSpecificProperty() private static method

private static FindMostSpecificProperty ( PropertyInfo cur1, PropertyInfo cur2 ) : int
cur1 System.Reflection.PropertyInfo
cur2 System.Reflection.PropertyInfo
return int
        public override PropertyInfo SelectProperty(BindingFlags bindingAttr, PropertyInfo[] match, Type returnType, Type[] indexes, ParameterModifier[] modifiers)
        {
            if (indexes != null)
            {
                if (!Contract.ForAll <Type>(indexes, (Type t) => t != null))
                {
                    Exception ex = new ArgumentNullException("indexes");
                    throw ex;
                }
            }
            if (match == null || match.Length == 0)
            {
                throw new ArgumentException(Environment.GetResourceString("Arg_EmptyArray"), "match");
            }
            PropertyInfo[] array = (PropertyInfo[])match.Clone();
            int            i     = 0;
            int            num   = 0;
            int            num2  = (indexes != null) ? indexes.Length : 0;
            int            j     = 0;

            while (j < array.Length)
            {
                if (indexes == null)
                {
                    goto IL_118;
                }
                ParameterInfo[] indexParameters = array[j].GetIndexParameters();
                if (indexParameters.Length == num2)
                {
                    for (i = 0; i < num2; i++)
                    {
                        Type parameterType = indexParameters[i].ParameterType;
                        if (!(parameterType == indexes[i]) && !(parameterType == typeof(object)))
                        {
                            if (parameterType.IsPrimitive)
                            {
                                if (!(indexes[i].UnderlyingSystemType is RuntimeType))
                                {
                                    break;
                                }
                                if (!DefaultBinder.CanConvertPrimitive((RuntimeType)indexes[i].UnderlyingSystemType, (RuntimeType)parameterType.UnderlyingSystemType))
                                {
                                    break;
                                }
                            }
                            else if (!parameterType.IsAssignableFrom(indexes[i]))
                            {
                                break;
                            }
                        }
                    }
                    goto IL_118;
                }
IL_182:
                j++;
                continue;
IL_118:
                if (i == num2)
                {
                    if (returnType != null)
                    {
                        if (array[j].PropertyType.IsPrimitive)
                        {
                            if (!(returnType.UnderlyingSystemType is RuntimeType))
                            {
                                goto IL_182;
                            }
                            if (!DefaultBinder.CanConvertPrimitive((RuntimeType)returnType.UnderlyingSystemType, (RuntimeType)array[j].PropertyType.UnderlyingSystemType))
                            {
                                goto IL_182;
                            }
                        }
                        else if (!array[j].PropertyType.IsAssignableFrom(returnType))
                        {
                            goto IL_182;
                        }
                    }
                    array[num++] = array[j];
                    goto IL_182;
                }
                goto IL_182;
            }
            if (num == 0)
            {
                return(null);
            }
            if (num == 1)
            {
                return(array[0]);
            }
            int  num3 = 0;
            bool flag = false;

            int[] array2 = new int[num2];
            for (j = 0; j < num2; j++)
            {
                array2[j] = j;
            }
            for (j = 1; j < num; j++)
            {
                int num4 = DefaultBinder.FindMostSpecificType(array[num3].PropertyType, array[j].PropertyType, returnType);
                if (num4 == 0 && indexes != null)
                {
                    num4 = DefaultBinder.FindMostSpecific(array[num3].GetIndexParameters(), array2, null, array[j].GetIndexParameters(), array2, null, indexes, null);
                }
                if (num4 == 0)
                {
                    num4 = DefaultBinder.FindMostSpecificProperty(array[num3], array[j]);
                    if (num4 == 0)
                    {
                        flag = true;
                    }
                }
                if (num4 == 2)
                {
                    flag = false;
                    num3 = j;
                }
            }
            if (flag)
            {
                throw new AmbiguousMatchException(Environment.GetResourceString("Arg_AmbiguousMatchException"));
            }
            return(array[num3]);
        }
Ejemplo n.º 2
0
        public override PropertyInfo SelectProperty(BindingFlags bindingAttr, PropertyInfo[] match, Type returnType, Type[] indexes, ParameterModifier[] modifiers)
        {
            if (indexes != null)
            {
                Type[]           typeArray  = indexes;
                Predicate <Type> predicate1 = (Predicate <Type>)(t => t != (Type)null);
                Predicate <Type> predicate2;
                if (!Contract.ForAll <Type>((IEnumerable <Type>)typeArray, predicate2))
                {
                    throw new ArgumentNullException("indexes");
                }
            }
            if (match == null || match.Length == 0)
            {
                throw new ArgumentException(Environment.GetResourceString("Arg_EmptyArray"), "match");
            }
            PropertyInfo[] propertyInfoArray = (PropertyInfo[])match.Clone();
            int            index1            = 0;
            int            num1   = 0;
            int            length = indexes != null ? indexes.Length : 0;

            for (int index2 = 0; index2 < propertyInfoArray.Length; ++index2)
            {
                if (indexes != null)
                {
                    ParameterInfo[] indexParameters = propertyInfoArray[index2].GetIndexParameters();
                    if (indexParameters.Length == length)
                    {
                        for (index1 = 0; index1 < length; ++index1)
                        {
                            Type parameterType = indexParameters[index1].ParameterType;
                            if (!(parameterType == indexes[index1]) && !(parameterType == typeof(object)))
                            {
                                if (parameterType.IsPrimitive)
                                {
                                    if (!(indexes[index1].UnderlyingSystemType is RuntimeType) || !DefaultBinder.CanConvertPrimitive((RuntimeType)indexes[index1].UnderlyingSystemType, (RuntimeType)parameterType.UnderlyingSystemType))
                                    {
                                        break;
                                    }
                                }
                                else if (!parameterType.IsAssignableFrom(indexes[index1]))
                                {
                                    break;
                                }
                            }
                        }
                    }
                    else
                    {
                        continue;
                    }
                }
                if (index1 == length)
                {
                    if (returnType != (Type)null)
                    {
                        if (propertyInfoArray[index2].PropertyType.IsPrimitive)
                        {
                            if (!(returnType.UnderlyingSystemType is RuntimeType) || !DefaultBinder.CanConvertPrimitive((RuntimeType)returnType.UnderlyingSystemType, (RuntimeType)propertyInfoArray[index2].PropertyType.UnderlyingSystemType))
                            {
                                continue;
                            }
                        }
                        else if (!propertyInfoArray[index2].PropertyType.IsAssignableFrom(returnType))
                        {
                            continue;
                        }
                    }
                    propertyInfoArray[num1++] = propertyInfoArray[index2];
                }
            }
            if (num1 == 0)
            {
                return((PropertyInfo)null);
            }
            if (num1 == 1)
            {
                return(propertyInfoArray[0]);
            }
            int  index3 = 0;
            bool flag   = false;

            int[] numArray = new int[length];
            for (int index2 = 0; index2 < length; ++index2)
            {
                numArray[index2] = index2;
            }
            for (int index2 = 1; index2 < num1; ++index2)
            {
                int num2 = DefaultBinder.FindMostSpecificType(propertyInfoArray[index3].PropertyType, propertyInfoArray[index2].PropertyType, returnType);
                if (num2 == 0 && indexes != null)
                {
                    num2 = DefaultBinder.FindMostSpecific(propertyInfoArray[index3].GetIndexParameters(), numArray, (Type)null, propertyInfoArray[index2].GetIndexParameters(), numArray, (Type)null, indexes, (object[])null);
                }
                if (num2 == 0)
                {
                    num2 = DefaultBinder.FindMostSpecificProperty(propertyInfoArray[index3], propertyInfoArray[index2]);
                    if (num2 == 0)
                    {
                        flag = true;
                    }
                }
                if (num2 == 2)
                {
                    flag   = false;
                    index3 = index2;
                }
            }
            if (flag)
            {
                throw new AmbiguousMatchException(Environment.GetResourceString("Arg_AmbiguousMatchException"));
            }
            return(propertyInfoArray[index3]);
        }