Beispiel #1
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]);
        }
        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]);
        }
Beispiel #3
0
        public override PropertyInfo SelectProperty(BindingFlags bindingAttr, PropertyInfo[] match, Type returnType, Type[] indexes, ParameterModifier[] modifiers)
        {
            int num;

            if ((indexes != null) && !Contract.ForAll <Type>(indexes, t => t != null))
            {
                throw new ArgumentNullException("indexes");
            }
            if ((match == null) || (match.Length == 0))
            {
                throw new ArgumentException(Environment.GetResourceString("Arg_EmptyArray"), "match");
            }
            PropertyInfo[] infoArray = (PropertyInfo[])match.Clone();
            int            index     = 0;
            int            num3      = 0;
            int            num4      = (indexes != null) ? indexes.Length : 0;

            for (num = 0; num < infoArray.Length; num++)
            {
                if (indexes != null)
                {
                    ParameterInfo[] indexParameters = infoArray[num].GetIndexParameters();
                    if (indexParameters.Length != num4)
                    {
                        continue;
                    }
                    index = 0;
                    while (index < num4)
                    {
                        Type parameterType = indexParameters[index].ParameterType;
                        if ((parameterType != indexes[index]) && (parameterType != typeof(object)))
                        {
                            if (parameterType.IsPrimitive)
                            {
                                if (!(indexes[index].UnderlyingSystemType is RuntimeType) || !CanConvertPrimitive((RuntimeType)indexes[index].UnderlyingSystemType, (RuntimeType)parameterType.UnderlyingSystemType))
                                {
                                    break;
                                }
                            }
                            else if (!parameterType.IsAssignableFrom(indexes[index]))
                            {
                                break;
                            }
                        }
                        index++;
                    }
                }
                if (index != num4)
                {
                    continue;
                }
                if (returnType != null)
                {
                    if (infoArray[num].PropertyType.IsPrimitive)
                    {
                        if ((returnType.UnderlyingSystemType is RuntimeType) && CanConvertPrimitive((RuntimeType)returnType.UnderlyingSystemType, (RuntimeType)infoArray[num].PropertyType.UnderlyingSystemType))
                        {
                            goto Label_0173;
                        }
                        continue;
                    }
                    if (!infoArray[num].PropertyType.IsAssignableFrom(returnType))
                    {
                        continue;
                    }
                }
Label_0173:
                infoArray[num3++] = infoArray[num];
            }
            switch (num3)
            {
            case 0:
                return(null);

            case 1:
                return(infoArray[0]);
            }
            int  num5 = 0;
            bool flag = false;

            int[] numArray = new int[num4];
            for (num = 0; num < num4; num++)
            {
                numArray[num] = num;
            }
            for (num = 1; num < num3; num++)
            {
                int num6 = FindMostSpecificType(infoArray[num5].PropertyType, infoArray[num].PropertyType, returnType);
                if ((num6 == 0) && (indexes != null))
                {
                    num6 = FindMostSpecific(infoArray[num5].GetIndexParameters(), numArray, null, infoArray[num].GetIndexParameters(), numArray, null, indexes, null);
                }
                if (num6 == 0)
                {
                    num6 = FindMostSpecificProperty(infoArray[num5], infoArray[num]);
                    if (num6 == 0)
                    {
                        flag = true;
                    }
                }
                if (num6 == 2)
                {
                    flag = false;
                    num5 = num;
                }
            }
            if (flag)
            {
                throw new AmbiguousMatchException(Environment.GetResourceString("Arg_AmbiguousMatchException"));
            }
            return(infoArray[num5]);
        }