2003-07-16 Gonzalo Paniagua Javier <gonzalo@ximian.com>
[mono.git] / mcs / mbas / pending.cs
index 82f8e3b84f67a9cc5961adf62d069ebbd656b50e..cd453dd4ce11d71adca05169b6d67b5d403c4631 100644 (file)
@@ -206,6 +206,7 @@ namespace Mono.CSharp {
                        // TypeBuilder.
                        //
                        ifaces = type_builder.GetInterfaces ();
+
 #if DEBUG
                        {
                                Type x = type_builder;
@@ -433,6 +434,45 @@ namespace Mono.CSharp {
                        container.TypeBuilder.DefineMethodOverride (proxy, iface_method);
                }
                
+               static bool IsPropertyGetMethod (string m)
+               {
+                       return (m.Substring (0, 4) == "get_");  
+               }
+
+               static bool IsPropertySetMethod (string m)
+               {
+                       return (m.Substring (0, 4) == "set_");  
+               }
+
+               MethodInfo FindExplicitImplementation (string iface_name, string method_name)
+               {
+                       if (container.Properties != null) {
+                               foreach (Property p in container.Properties) 
+                               {
+                                       if (p.Implements != null) {                                     
+                                               if (IsPropertyGetMethod (method_name) && (container.Namespace.Name +  "." + p.Implements.ToString() == iface_name + "." + method_name.Substring(4))) 
+                                                               return p.PropertyBuilder.GetGetMethod(true);
+
+                                               if (IsPropertySetMethod (method_name) && (container.Namespace.Name +  "." + p.Implements.ToString() == iface_name + "." + method_name.Substring(4))) 
+                                                               return p.PropertyBuilder.GetSetMethod(true);
+                                       }
+                               }
+                       }
+
+                       if (container.Methods != null) 
+                       {
+                               foreach (Method m in container.Methods) 
+                               {
+                                       if (m.Implements != null) 
+                                       {                                       
+                                               if (container.Namespace.Name +  "." + m.Implements.ToString() == iface_name + "." + method_name)
+                                                       return (MethodInfo) m.MethodBuilder;
+                                       }
+                               }
+                       }
+                       return null;
+               }
+
                /// <summary>
                ///   This function tells whether one of our parent classes implements
                ///   the given method (which turns out, it is valid to have an interface
@@ -441,19 +481,27 @@ namespace Mono.CSharp {
                bool ParentImplements (Type iface_type, MethodInfo mi)
                {
                        MethodSignature ms;
+                       MethodInfo mr;
                        
                        Type [] args = TypeManager.GetArgumentTypes (mi);
+
                        ms = new MethodSignature (mi.Name, mi.ReturnType, args);
                        MemberList list = TypeContainer.FindMembers (
                                container.TypeBuilder.BaseType, MemberTypes.Method | MemberTypes.Property,
                                BindingFlags.Public | BindingFlags.Instance,
                                MethodSignature.method_signature_filter, ms);
 
-                       if (list.Count == 0)
-                               return false;
+                       if (list.Count == 0) 
+                       {
+                               mr = FindExplicitImplementation (iface_type.ToString(), mi.Name);
+                               if (mr == null)
+                                       return false;
+                       }
+                       else
+                               mr = (MethodInfo) list[0];
 
-                       DefineProxy (iface_type, (MethodInfo) list [0], mi, args);
-                       return true;
+                       DefineProxy (iface_type, mr, mi, args);
+                       return true;                                            
                }
 
                /// <summary>