2003-01-09 Gonzalo Paniagua Javier <gonzalo@ximian.com>
[mono.git] / mcs / class / corlib / System / Type.cs
index 13e39daa64f3ba6e55040bc45baa5ab2ffcfdeea..62e8d0f6e7e04f14ba3d209c676008aea69d9d31 100644 (file)
@@ -102,10 +102,9 @@ namespace System {
                /// <summary>
                ///
                /// </summary>
-               [MonoTODO]
                public static Binder DefaultBinder {
                        get {
-                               return null;
+                               return Binder.DefaultBinder;
                        }
                }
                
@@ -358,24 +357,40 @@ namespace System {
                
                [MethodImplAttribute(MethodImplOptions.InternalCall)]
                private static extern Type internal_from_handle (RuntimeTypeHandle handle);
-               [MethodImplAttribute(MethodImplOptions.InternalCall)]
-               private static extern Type internal_from_name (string name);
                
+               [MethodImplAttribute(MethodImplOptions.InternalCall)]
+               private static extern Type internal_from_name (string name, bool throwOnError, bool ignoreCase);
+
                public static Type GetType(string typeName)
                {
-                       return internal_from_name (typeName);
+                       if (typeName == null)
+                               throw new ArgumentNullException ("typeName");
+
+                       return internal_from_name (typeName, false, false);
                }
 
                public static Type GetType(string typeName, bool throwOnError)
                {
-                       // LAMESPEC: what kinds of errors cause exception to be thrown?
-                       return internal_from_name (typeName);
+                       if (typeName == null)
+                               throw new ArgumentNullException ("typeName");
+
+                       Type type = internal_from_name (typeName, throwOnError, false);
+                       if (throwOnError && type == null)
+                               throw new TypeLoadException ("Error loading '" + typeName + "'");
+
+                       return type;
                }
 
-               [MonoTODO]
                public static Type GetType(string typeName, bool throwOnError, bool ignoreCase)
                {
-                       throw new NotImplementedException ();
+                       if (typeName == null)
+                               throw new ArgumentNullException ("typeName");
+
+                       Type t = internal_from_name (typeName, throwOnError, ignoreCase);
+                       if (throwOnError && t == null)
+                               throw new TypeLoadException ("Error loading '" + typeName + "'");
+
+                       return t;
                }
 
                public static Type[] GetTypeArray (object[] args) {
@@ -455,14 +470,24 @@ namespace System {
                
                public virtual bool IsSubclassOf (Type c)
                {
-                       return type_is_subtype_of (this, c, false);
+                       if (c == null)
+                               throw new ArgumentNullException ("c");
+
+                       return !Equals (c) && type_is_subtype_of (this, c, false);
                }
 
-               [MonoTODO]
                public virtual Type[] FindInterfaces (TypeFilter filter, object filterCriteria)
                {
-                       // FIXME
-                       throw new NotImplementedException ();
+                       if (filter == null)
+                               throw new ArgumentNullException ("filter");
+
+                       ArrayList ifaces = new ArrayList ();
+                       foreach (Type iface in GetInterfaces ()) {
+                               if (filter (iface, filterCriteria))
+                                       ifaces.Add (iface);
+                       }
+
+                       return (Type []) ifaces.ToArray (typeof (Type));
                }
                
                public Type GetInterface (string name) {
@@ -471,19 +496,36 @@ namespace System {
 
                public abstract Type GetInterface (string name, bool ignoreCase);
 
+               [MethodImplAttribute(MethodImplOptions.InternalCall)]
+               internal static extern void GetInterfaceMapData (Type t, Type iface, out MethodInfo[] targets, out MethodInfo[] methods);
+               
                public virtual InterfaceMapping GetInterfaceMap (Type interfaceType) {
-                       throw new NotImplementedException ();
+                       InterfaceMapping res;
+                       if (interfaceType == null)
+                               throw new ArgumentNullException ("interfaceType");
+                       if (!interfaceType.IsInterface)
+                               throw new ArgumentException ("type argument must be an interface", "interfaceType");
+                       res.TargetType = this;
+                       res.InterfaceType = interfaceType;
+                       GetInterfaceMapData (this, interfaceType, out res.TargetMethods, out res.InterfaceMethods);
+                       if (res.TargetMethods == null)
+                               throw new ArgumentException ("interface not found", "interfaceType");
+
+                       return res;
                }
 
                public abstract Type[] GetInterfaces ();
 
                public virtual bool IsAssignableFrom (Type c)
                {
+                       if (c == null)
+                               return false;
+
                        if (Equals (c))
                                return true;
 
                        if (type_is_subtype_of (c, this, true))
-                               return true;;
+                               return true;
 
                        if (!IsInterface)
                                return false;
@@ -642,9 +684,6 @@ namespace System {
 
                public abstract PropertyInfo[] GetProperties (BindingFlags bindingAttr);
 
-               [MethodImplAttribute(MethodImplOptions.InternalCall)]
-               private static extern PropertyInfo get_property (Type type, string name, Type[] types);
-               
 
                public PropertyInfo GetProperty (string name)
                {
@@ -668,11 +707,9 @@ namespace System {
                        return GetPropertyImpl (name, DefaultBindingFlags, null, returnType, new Type[0], null);
                }
 
-               [MonoTODO]
                public PropertyInfo GetProperty (string name, Type[] types)
                {
-                       // TODO: return GetProperty (name, DefaultBindingFlags, null, null, types, null);
-                       return get_property (this, name, types);
+                       return GetProperty (name, DefaultBindingFlags, null, null, types, null);
                }
 
                public PropertyInfo GetProperty (string name, Type returnType, Type[] types)
@@ -761,15 +798,19 @@ namespace System {
 
                public ConstructorInfo[] GetConstructors ()
                {
-                       return GetConstructors (BindingFlags.Public | BindingFlags.NonPublic);
+                       return GetConstructors (BindingFlags.Public | BindingFlags.Instance);
                }
                
                public abstract ConstructorInfo[] GetConstructors (BindingFlags bindingAttr);
 
-               [MonoTODO]
                public virtual MemberInfo[] GetDefaultMembers ()
                {
-                       throw new NotImplementedException ();
+                       object [] att = GetCustomAttributes (typeof (DefaultMemberAttribute), true);
+                       if (att.Length == 0)
+                               return new MemberInfo [0];
+
+                       MemberInfo [] member = GetMember (((DefaultMemberAttribute) att [0]).MemberName);
+                       return (member != null) ? member : new MemberInfo [0];
                }
 
                public virtual MemberInfo[] FindMembers (MemberTypes memberType, BindingFlags bindingAttr,