Moved ProviderCollectionTest.cs from System assembly to System.Configuration.
[mono.git] / mcs / class / corlib / System.Reflection / Binder.cs
index 614aa4dc4e15d99228e7213e9796cf6d715f934b..898d4ad38489227329ceb132e21f1772fef0f7aa 100644 (file)
@@ -100,9 +100,33 @@ namespace System.Reflection
 
                        for (int current = 0; current < count; current++) 
                        {
-                               int level = GetDerivedLevel (match[current].DeclaringType);
+                               MethodBase m = match [current];
+                               int level = GetDerivedLevel (m.DeclaringType);
                                if (level == highLevel)
                                        throw new AmbiguousMatchException ();
+                               // If the argument types differ we
+                               // have an ambigous match, as well
+                               if (matchId >= 0) {
+                                       ParameterInfo[] p1 = m.GetParameters ();
+                                       ParameterInfo[] p2 = match [matchId].GetParameters ();
+                                       bool equal = true;
+
+                                       if (p1.Length != p2.Length)
+                                               equal = false;
+                                       else {
+                                               int i;
+
+                                               for (i = 0; i < p1.Length; ++i) {
+                                                       if (p1 [i].ParameterType != p2 [i].ParameterType) {
+                                                               equal = false;
+                                                               break;
+                                                       }
+                                               }
+                                       }
+
+                                       if (!equal)
+                                               throw new AmbiguousMatchException ();
+                               }
 
                                if (level > highLevel) 
                                {
@@ -188,8 +212,18 @@ namespace System.Reflection
                                                return value;
                                }
 
-                               if (check_type (vtype, type))
+                               if (check_type (vtype, type)) {
+                                       // These are not supported by Convert
+                                       if (type.IsEnum)
+                                               return Enum.ToObject (type, value);
+                                       if (vtype == typeof (Char)) {
+                                               if (type == typeof (double))
+                                                       return (double)(char)value;
+                                               if (type == typeof (float))
+                                                       return (float)(char)value;
+                                       }
                                        return Convert.ChangeType (value, type);
+                               }
                                return null;
                        }
 
@@ -207,15 +241,21 @@ namespace System.Reflection
                                if (from == null)
                                        return true;
 
-                               TypeCode fromt = Type.GetTypeCode (from);
-                               TypeCode tot = Type.GetTypeCode (to);
-
                                if (to.IsByRef != from.IsByRef)
                                        return false;
 
                                if (to.IsInterface)
                                        return to.IsAssignableFrom (from);
 
+                               if (to.IsEnum) {
+                                       to = Enum.GetUnderlyingType (to);
+                                       if (from == to)
+                                               return true;
+                               }
+
+                               TypeCode fromt = Type.GetTypeCode (from);
+                               TypeCode tot = Type.GetTypeCode (to);
+
                                switch (fromt) {
                                case TypeCode.Char:
                                        switch (tot) {
@@ -325,33 +365,39 @@ namespace System.Reflection
                                if (match == null)
                                        throw new ArgumentNullException ("match");
 
+                               /* first look for an exact match... */
+                               for (i = 0; i < match.Length; ++i) {
+                                       m = match [i];
+                                       ParameterInfo[] args = m.GetParameters ();
+                                       if (args.Length != types.Length)
+                                               continue;
+                                       for (j = 0; j < types.Length; ++j) {
+                                               if (types [j] != args [j].ParameterType)
+                                                       break;
+                                       }
+                                       if (j == types.Length)
+                                               return m;
+                               }
+
+                               /* Try methods with ParamArray attribute */
                                bool isdefParamArray = false;
                                Type elementType = null;
-
-                               /* first look for an exact match... */
                                for (i = 0; i < match.Length; ++i) {
                                        m = match [i];
                                        ParameterInfo[] args = m.GetParameters ();
                                        if (args.Length > types.Length)
                                                continue;
-                                       else if(args.Length <= types.Length & args.Length > 0)
-                                       {
-                                               isdefParamArray = Attribute.IsDefined (args [args.Length - 1], typeof (ParamArrayAttribute));
-                                               if (isdefParamArray)
-                                                       elementType = args [args.Length - 1].ParameterType.GetElementType ();
-                                               if (args.Length != types.Length & !isdefParamArray)
-                                                       continue;
-                                       }else if(args.Length == 0 & types.Length > 0)
+                                       else if (args.Length == 0)
+                                               continue;
+                                       isdefParamArray = Attribute.IsDefined (args [args.Length - 1], typeof (ParamArrayAttribute));
+                                       if (!isdefParamArray)
                                                continue;
+                                       elementType = args [args.Length - 1].ParameterType.GetElementType ();
                                        for (j = 0; j < types.Length; ++j) {
-                                               if (!isdefParamArray && types [j] != args [j].ParameterType)
+                                               if (j < (args.Length - 1) && types [j] != args [j].ParameterType)
+                                                       break;
+                                               else if (j >= (args.Length - 1) && types [j] != elementType) 
                                                        break;
-                                               else if (isdefParamArray) {
-                                                       if (j < (args.Length - 1) && types [j] != args [j].ParameterType)
-                                                               break;
-                                                       else if (j >= (args.Length - 1) && types [j] != elementType) 
-                                                               break;
-                                               }
                                        }
                                        if (j == types.Length)
                                                return m;
@@ -469,7 +515,7 @@ namespace System.Reflection
                                        if (idxlen >= 0 && idxlen != args.Length)
                                                continue;
 
-                                       if (haveRet && !check_type (p.PropertyType, returnType))
+                                       if (haveRet && p.PropertyType != returnType)
                                                continue;
 
                                        int score = Int32.MaxValue - 1;