From d7b1a66b945f37e7a62ce28a2cbb4618dbca842b Mon Sep 17 00:00:00 2001 From: Zoltan Varga Date: Tue, 12 Aug 2008 19:46:06 +0000 Subject: Merge r110288 from HEAD. svn path=/branches/mono-2-0/mcs/; revision=110291 --- mcs/class/corlib/System.Reflection.Emit/ChangeLog | 5 +++++ mcs/class/corlib/System.Reflection.Emit/TypeBuilder.cs | 16 +++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/mcs/class/corlib/System.Reflection.Emit/ChangeLog b/mcs/class/corlib/System.Reflection.Emit/ChangeLog index d1fc3f81976..df8bab39c61 100644 --- a/mcs/class/corlib/System.Reflection.Emit/ChangeLog +++ b/mcs/class/corlib/System.Reflection.Emit/ChangeLog @@ -1,3 +1,8 @@ +2008-08-12 Zoltan Varga + + * TypeBuilder.cs (CreateType): Avoid creating a default ctor if the + type has a constructor defined using DefineMethod. Fixes #416632. + 2008-07-11 Marek Safar * ModuleBuilder.cs: Couple of micro optimizations. diff --git a/mcs/class/corlib/System.Reflection.Emit/TypeBuilder.cs b/mcs/class/corlib/System.Reflection.Emit/TypeBuilder.cs index e3042138882..f1790048c80 100644 --- a/mcs/class/corlib/System.Reflection.Emit/TypeBuilder.cs +++ b/mcs/class/corlib/System.Reflection.Emit/TypeBuilder.cs @@ -751,6 +751,20 @@ namespace System.Reflection.Emit } return false; } + + // Return whenever this type has a ctor defined using DefineMethod () + private bool has_ctor_method () { + MethodAttributes ctor_attrs = MethodAttributes.SpecialName | MethodAttributes.RTSpecialName; + + for (int i = 0; i < num_methods; ++i) { + MethodBuilder mb = (MethodBuilder)(methods[i]); + + if (mb.Name == ConstructorInfo.ConstructorName && (mb.Attributes & ctor_attrs) == ctor_attrs) + return true; + } + + return false; + } public Type CreateType() { @@ -804,7 +818,7 @@ namespace System.Reflection.Emit // On classes, define a default constructor if not provided // if (!(IsInterface || IsValueType) && (ctors == null) && (tname != "") && - (GetAttributeFlagsImpl () & TypeAttributes.Abstract | TypeAttributes.Sealed) != (TypeAttributes.Abstract | TypeAttributes.Sealed)) + (GetAttributeFlagsImpl () & TypeAttributes.Abstract | TypeAttributes.Sealed) != (TypeAttributes.Abstract | TypeAttributes.Sealed) && !has_ctor_method ()) DefineDefaultConstructor (MethodAttributes.Public); if (ctors != null){ -- cgit v1.2.3