Bring jbevain/cecil's commit 5490b9bc05bd2efa8ed0e18f1c2da10e8e75f56b, Fix ThisParame...
authorMiguel de Icaza <miguel@gnome.org>
Wed, 18 Apr 2012 22:32:38 +0000 (18:32 -0400)
committerMiguel de Icaza <miguel@gnome.org>
Wed, 18 Apr 2012 22:54:15 +0000 (18:54 -0400)
mcs/class/Mono.Cecil/Mono.Cecil.Cil/MethodBody.cs

index e74866be666bd443ac260dfdf2aa8679dbfb9972..32442f878a0c09d48a781fed4f736071dae404fb 100644 (file)
@@ -100,11 +100,19 @@ namespace Mono.Cecil.Cil {
                                if (method == null || method.DeclaringType == null)
                                        throw new NotSupportedException ();
 
-                               if (this_parameter == null) {
-                                       this_parameter = new ParameterDefinition (method.DeclaringType);
-                                       this_parameter.method = method;
-                               }
+                               if (!method.HasThis)
+                                       return null;
 
+                               if (this_parameter != null)
+                                       return this_parameter;
+
+                               var declaring_type = method.DeclaringType;
+                               var type = declaring_type.IsValueType || declaring_type.IsPrimitive
+                                       ? new PointerType (declaring_type)
+                                       : declaring_type as TypeReference;
+
+                               this_parameter = new ParameterDefinition (type);
+                               this_parameter.method = method;
                                return this_parameter;
                        }
                }