Author: jbevain
Date: 2006-09-24 10:03:22 -0400 (Sun, 24 Sep 2006)
New Revision: 65852

Modified:
   trunk/cecil/lib/ChangeLog
   trunk/cecil/lib/CodeGen/templates/IndexedCollection.cs
   trunk/cecil/lib/Mono.Cecil/ConstructorCollection.cs
   trunk/cecil/lib/Mono.Cecil/MethodDefinitionCollection.cs
Log:
2006-09-20  Jb Evain  <[EMAIL PROTECTED]>

        * Mono.Cecil/MethodDefinitionCollection.cs
          Mono.Cecil/ConstructorCollection.cs
          CodeGen/templates/IndexedCollection.cs:
                Fix the GetConstructor/GetMethod methods.
                Based on a patch by Jon Chambers.


Modified: trunk/cecil/lib/ChangeLog
===================================================================
--- trunk/cecil/lib/ChangeLog   2006-09-24 13:03:14 UTC (rev 65851)
+++ trunk/cecil/lib/ChangeLog   2006-09-24 14:03:22 UTC (rev 65852)
@@ -1,5 +1,13 @@
 2006-09-20  Jb Evain  <[EMAIL PROTECTED]>
 
+       * Mono.Cecil/MethodDefinitionCollection.cs
+         Mono.Cecil/ConstructorCollection.cs
+         CodeGen/templates/IndexedCollection.cs:
+               Fix the GetConstructor/GetMethod methods.
+               Based on a patch by Jon Chambers.
+
+2006-09-20  Jb Evain  <[EMAIL PROTECTED]>
+
        * Mono.Cecil/StructureWriter.cs
          Mono.Cecil/ModuleDefinition.cs
          Mono.Cecil/ReflectionWriter.cs

Modified: trunk/cecil/lib/CodeGen/templates/IndexedCollection.cs
===================================================================
--- trunk/cecil/lib/CodeGen/templates/IndexedCollection.cs      2006-09-24 
13:03:14 UTC (rev 65851)
+++ trunk/cecil/lib/CodeGen/templates/IndexedCollection.cs      2006-09-24 
14:03:22 UTC (rev 65852)
@@ -165,43 +165,51 @@
                        return ret.ToArray (typeof (MethodDefinition)) as 
MethodDefinition [];
                }
 
-               public MethodDefinition GetMethod (string name, Type [] 
parameters)
+               internal MethodDefinition GetMethod (string name, IList 
parameters)
                {
-                       foreach (MethodDefinition meth in this)
-                               if (meth.Name == name && meth.Parameters.Count 
== parameters.Length) {
-                                       if (parameters.Length == 0)
-                                               return meth;
-                                       for (int i = 0; i < parameters.Length; 
i++)
-                                               if (meth.Parameters 
[i].ParameterType.FullName == ReflectionHelper.GetTypeSignature (parameters 
[i]))
-                                                       return meth;
+                       foreach (MethodDefinition meth in this) {
+                               if (meth.Name != name || meth.Parameters.Count 
!= parameters.Count)
+                                       continue;
+
+                               bool match = true;
+                               for (int i = 0; i < parameters.Count; i++) {
+                                       string pname;
+                                       object param = parameters [i];
+                                       if (param is Type)
+                                               pname = 
ReflectionHelper.GetTypeSignature (param as Type);
+                                       else if (param is TypeReference)
+                                               pname = (param as 
TypeReference).FullName;
+                                       else if (param is ParameterDefinition)
+                                               pname = (param as 
ParameterDefinition).ParameterType.FullName;
+                                       else
+                                               throw new NotSupportedException 
();
+ 
+                                       if (meth.Parameters 
[i].ParameterType.FullName != pname) {
+                                               match = false;
+                                               break;
+                                       }
                                }
+
+                               if (match)
+                                       return meth;
+                       }
+
                        return null;
                }
 
+               public MethodDefinition GetMethod (string name, Type [] 
parameters)
+               {
+                       return GetMethod (name, parameters);
+               }
+
                public MethodDefinition GetMethod (string name, TypeReference 
[] parameters)
                {
-                       foreach (MethodDefinition meth in this)
-                               if (meth.Name == name && meth.Parameters.Count 
== parameters.Length) {
-                                       if (parameters.Length == 0)
-                                               return meth;
-                                       for (int i = 0; i < parameters.Length; 
i++)
-                                               if (meth.Parameters 
[i].ParameterType.FullName == parameters [i].FullName)
-                                                       return meth;
-                               }
-                       return null;
+                       return GetMethod (name, parameters);
                }
 
                public MethodDefinition GetMethod (string name, 
ParameterDefinitionCollection parameters)
                {
-                       foreach (MethodDefinition meth in this)
-                               if (meth.Name == name && meth.Parameters.Count 
== parameters.Count) {
-                                       if (parameters.Count == 0)
-                                               return meth;
-                                       for (int i = 0; i < parameters.Count; 
i++)
-                                               if (meth.Parameters 
[i].ParameterType.FullName == parameters [i].ParameterType.FullName)
-                                                       return meth;
-                               }
-                       return null;
+                       return GetMethod (name, parameters);
                }
 <%
                when "FieldDefinition"
@@ -217,43 +225,51 @@
 <%
                when "Constructor"
 %>
-               public MethodDefinition GetConstructor (bool isStatic, Type [] 
parameters)
+               internal MethodDefinition GetConstructor (bool isStatic, IList 
parameters)
                {
                        foreach (MethodDefinition ctor in this) {
-                               if (ctor.IsStatic == isStatic && 
ctor.Parameters.Count == parameters.Length) {
-                                       if (parameters.Length == 0)
-                                               return ctor;
-                                       for (int i = 0; i < parameters.Length; 
i++)
-                                               if (ctor.Parameters 
[i].ParameterType.FullName ==  ReflectionHelper.GetTypeSignature (parameters 
[i]))
-                                                       return ctor;
+                               if (ctor.IsStatic != isStatic || 
ctor.Parameters.Count != parameters.Count)
+                                       continue;
+
+                               bool match = true;
+                               for (int i = 0; i < parameters.Count; i++) {
+                                       string pname;
+                                       object param = parameters [i];
+                                       if (param is Type)
+                                               pname = 
ReflectionHelper.GetTypeSignature (param as Type);
+                                       else if (param is TypeReference)
+                                               pname = (param as 
TypeReference).FullName;
+                                       else if (param is ParameterDefinition)
+                                               pname = (param as 
ParameterDefinition).ParameterType.FullName;
+                                       else
+                                               throw new NotSupportedException 
();
+ 
+                                       if (ctor.Parameters 
[i].ParameterType.FullName != pname) {
+                                               match = false;
+                                               break;
+                                       }
                                }
+
+                               if (match)
+                                       return ctor;
                        }
 
                        return null;
                }
 
+               public MethodDefinition GetConstructor (bool isStatic, Type [] 
parameters)
+               {
+                       return GetConstructor (isStatic, parameters);
+               }
+
                public MethodDefinition GetConstructor (bool isStatic, 
TypeReference [] parameters)
                {
-                       foreach (MethodDefinition ctor in this)
-                               if (ctor.IsStatic == isStatic && 
ctor.Parameters.Count == parameters.Length)
-                                       for (int i = 0; i < parameters.Length; 
i++)
-                                               if (ctor.Parameters 
[i].ParameterType.FullName == parameters [i].FullName)
-                                                       return ctor;
-
-                       return null;
+                       return GetConstructor (isStatic, parameters);
                }
 
                public MethodDefinition GetConstructor (bool isStatic, 
ParameterDefinitionCollection parameters)
                {
-                       foreach (MethodDefinition ctor in this)
-                               if (ctor.IsStatic == isStatic && 
ctor.Parameters.Count == parameters.Count) {
-                                       if (parameters.Count == 0)
-                                               return ctor;
-                                       for (int i = 0; i < parameters.Count; 
i++)
-                                               if (ctor.Parameters 
[i].ParameterType.FullName == parameters [i].ParameterType.FullName)
-                                                       return ctor;
-                               }
-                       return null;
+                       return GetConstructor (isStatic, parameters);
                }
 <%
                when "EventDefinition"

Modified: trunk/cecil/lib/Mono.Cecil/ConstructorCollection.cs
===================================================================
--- trunk/cecil/lib/Mono.Cecil/ConstructorCollection.cs 2006-09-24 13:03:14 UTC 
(rev 65851)
+++ trunk/cecil/lib/Mono.Cecil/ConstructorCollection.cs 2006-09-24 14:03:22 UTC 
(rev 65852)
@@ -5,7 +5,7 @@
 //   Jb Evain ([EMAIL PROTECTED])
 //
 // Generated by /CodeGen/cecil-gen.rb do not edit
-// Wed Sep 06 13:53:07 CEST 2006
+// Sun Sep 24 15:57:33 CEST 2006
 //
 // (C) 2005 Jb Evain
 //
@@ -131,43 +131,51 @@
                        return m_items.GetEnumerator ();
                }
 
-               public MethodDefinition GetConstructor (bool isStatic, Type [] 
parameters)
+               internal MethodDefinition GetConstructor (bool isStatic, IList 
parameters)
                {
                        foreach (MethodDefinition ctor in this) {
-                               if (ctor.IsStatic == isStatic && 
ctor.Parameters.Count == parameters.Length) {
-                                       if (parameters.Length == 0)
-                                               return ctor;
-                                       for (int i = 0; i < parameters.Length; 
i++)
-                                               if (ctor.Parameters 
[i].ParameterType.FullName ==  ReflectionHelper.GetTypeSignature (parameters 
[i]))
-                                                       return ctor;
+                               if (ctor.IsStatic != isStatic || 
ctor.Parameters.Count != parameters.Count)
+                                       continue;
+
+                               bool match = true;
+                               for (int i = 0; i < parameters.Count; i++) {
+                                       string pname;
+                                       object param = parameters [i];
+                                       if (param is Type)
+                                               pname = 
ReflectionHelper.GetTypeSignature (param as Type);
+                                       else if (param is TypeReference)
+                                               pname = (param as 
TypeReference).FullName;
+                                       else if (param is ParameterDefinition)
+                                               pname = (param as 
ParameterDefinition).ParameterType.FullName;
+                                       else
+                                               throw new NotSupportedException 
();
+ 
+                                       if (ctor.Parameters 
[i].ParameterType.FullName != pname) {
+                                               match = false;
+                                               break;
+                                       }
                                }
+
+                               if (match)
+                                       return ctor;
                        }
 
                        return null;
                }
 
+               public MethodDefinition GetConstructor (bool isStatic, Type [] 
parameters)
+               {
+                       return GetConstructor (isStatic, parameters);
+               }
+
                public MethodDefinition GetConstructor (bool isStatic, 
TypeReference [] parameters)
                {
-                       foreach (MethodDefinition ctor in this)
-                               if (ctor.IsStatic == isStatic && 
ctor.Parameters.Count == parameters.Length)
-                                       for (int i = 0; i < parameters.Length; 
i++)
-                                               if (ctor.Parameters 
[i].ParameterType.FullName == parameters [i].FullName)
-                                                       return ctor;
-
-                       return null;
+                       return GetConstructor (isStatic, parameters);
                }
 
                public MethodDefinition GetConstructor (bool isStatic, 
ParameterDefinitionCollection parameters)
                {
-                       foreach (MethodDefinition ctor in this)
-                               if (ctor.IsStatic == isStatic && 
ctor.Parameters.Count == parameters.Count) {
-                                       if (parameters.Count == 0)
-                                               return ctor;
-                                       for (int i = 0; i < parameters.Count; 
i++)
-                                               if (ctor.Parameters 
[i].ParameterType.FullName == parameters [i].ParameterType.FullName)
-                                                       return ctor;
-                               }
-                       return null;
+                       return GetConstructor (isStatic, parameters);
                }
 
                void Attach (MemberReference member)

Modified: trunk/cecil/lib/Mono.Cecil/MethodDefinitionCollection.cs
===================================================================
--- trunk/cecil/lib/Mono.Cecil/MethodDefinitionCollection.cs    2006-09-24 
13:03:14 UTC (rev 65851)
+++ trunk/cecil/lib/Mono.Cecil/MethodDefinitionCollection.cs    2006-09-24 
14:03:22 UTC (rev 65852)
@@ -5,7 +5,7 @@
 //   Jb Evain ([EMAIL PROTECTED])
 //
 // Generated by /CodeGen/cecil-gen.rb do not edit
-// Wed Sep 06 13:53:07 CEST 2006
+// Sun Sep 24 15:57:33 CEST 2006
 //
 // (C) 2005 Jb Evain
 //
@@ -141,43 +141,51 @@
                        return ret.ToArray (typeof (MethodDefinition)) as 
MethodDefinition [];
                }
 
-               public MethodDefinition GetMethod (string name, Type [] 
parameters)
+               internal MethodDefinition GetMethod (string name, IList 
parameters)
                {
-                       foreach (MethodDefinition meth in this)
-                               if (meth.Name == name && meth.Parameters.Count 
== parameters.Length) {
-                                       if (parameters.Length == 0)
-                                               return meth;
-                                       for (int i = 0; i < parameters.Length; 
i++)
-                                               if (meth.Parameters 
[i].ParameterType.FullName == ReflectionHelper.GetTypeSignature (parameters 
[i]))
-                                                       return meth;
+                       foreach (MethodDefinition meth in this) {
+                               if (meth.Name != name || meth.Parameters.Count 
!= parameters.Count)
+                                       continue;
+
+                               bool match = true;
+                               for (int i = 0; i < parameters.Count; i++) {
+                                       string pname;
+                                       object param = parameters [i];
+                                       if (param is Type)
+                                               pname = 
ReflectionHelper.GetTypeSignature (param as Type);
+                                       else if (param is TypeReference)
+                                               pname = (param as 
TypeReference).FullName;
+                                       else if (param is ParameterDefinition)
+                                               pname = (param as 
ParameterDefinition).ParameterType.FullName;
+                                       else
+                                               throw new NotSupportedException 
();
+ 
+                                       if (meth.Parameters 
[i].ParameterType.FullName != pname) {
+                                               match = false;
+                                               break;
+                                       }
                                }
+
+                               if (match)
+                                       return meth;
+                       }
+
                        return null;
                }
 
+               public MethodDefinition GetMethod (string name, Type [] 
parameters)
+               {
+                       return GetMethod (name, parameters);
+               }
+
                public MethodDefinition GetMethod (string name, TypeReference 
[] parameters)
                {
-                       foreach (MethodDefinition meth in this)
-                               if (meth.Name == name && meth.Parameters.Count 
== parameters.Length) {
-                                       if (parameters.Length == 0)
-                                               return meth;
-                                       for (int i = 0; i < parameters.Length; 
i++)
-                                               if (meth.Parameters 
[i].ParameterType.FullName == parameters [i].FullName)
-                                                       return meth;
-                               }
-                       return null;
+                       return GetMethod (name, parameters);
                }
 
                public MethodDefinition GetMethod (string name, 
ParameterDefinitionCollection parameters)
                {
-                       foreach (MethodDefinition meth in this)
-                               if (meth.Name == name && meth.Parameters.Count 
== parameters.Count) {
-                                       if (parameters.Count == 0)
-                                               return meth;
-                                       for (int i = 0; i < parameters.Count; 
i++)
-                                               if (meth.Parameters 
[i].ParameterType.FullName == parameters [i].ParameterType.FullName)
-                                                       return meth;
-                               }
-                       return null;
+                       return GetMethod (name, parameters);
                }
 
                void Attach (MemberReference member)

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to