[Mono-bugs] [Bug 78855][Nor] New - SRE TypeBuilder.CreateType() does not emit custom attributes on properties
bugzilla-daemon at bugzilla.ximian.com
bugzilla-daemon at bugzilla.ximian.com
Fri Jul 14 07:35:47 EDT 2006
Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.
Changed by atsushi at ximian.com.
http://bugzilla.ximian.com/show_bug.cgi?id=78855
--- shadow/78855 2006-07-14 07:35:47.000000000 -0400
+++ shadow/78855.tmp.1445 2006-07-14 07:35:47.000000000 -0400
@@ -0,0 +1,85 @@
+Bug#: 78855
+Product: Mono: Class Libraries
+Version: 1.1
+OS:
+OS Details:
+Status: NEW
+Resolution:
+Severity:
+Priority: Normal
+Component: CORLIB
+AssignedTo: mono-bugs at ximian.com
+ReportedBy: atsushi at ximian.com
+QAContact: mono-bugs at ximian.com
+TargetMilestone: ---
+URL:
+Cc:
+Summary: SRE TypeBuilder.CreateType() does not emit custom attributes on properties
+
+When we create Type via TypeBuilder.CreateType(), the properties in the
+returned type do not contain custom attributes.
+
+--------
+using System;
+using System.Reflection;
+using System.Reflection.Emit;
+
+public class test
+{
+ public static void Main ()
+ {
+ AppDomain myDomain = System.Threading.Thread.GetDomain();
+ AssemblyName aname = new AssemblyName();
+ aname.Name = "bar";
+ AssemblyBuilder ab = myDomain.DefineDynamicAssembly (
+ aname, AssemblyBuilderAccess.RunAndSave);
+ ModuleBuilder mob = ab.DefineDynamicModule ("bar");
+ TypeBuilder tb = mob.DefineType ("blah2");
+
+ PropertyBuilder pb = tb.DefineProperty (
+ "whoa", PropertyAttributes.None, typeof (object), Type.EmptyTypes);
+ pb.SetGetMethod (tb.DefineMethod (
+ "get_whoa", MethodAttributes.Public, CallingConventions.Standard, typeof
+(object), Type.EmptyTypes));
+
+ ConstructorInfo ci = typeof (MyAttribute).GetConstructor (Type.EmptyTypes);
+
+ CustomAttributeBuilder cab = new CustomAttributeBuilder (
+ ci, new object [0],
+ new PropertyInfo [0], new object [0],
+ new FieldInfo [0], new object [0]);
+
+ pb.SetCustomAttribute (cab);
+
+ ILGenerator gen;
+ Label returnLabel;
+ MethodBuilder mb;
+
+ // getter
+ mb = (MethodBuilder) pb.GetGetMethod ();
+ if (mb != null) {
+ gen = mb.GetILGenerator ();
+ returnLabel = gen.DefineLabel ();
+ gen.MarkLabel (returnLabel);
+ gen.Emit (OpCodes.Ret);
+ }
+
+ Type type = tb.CreateType ();
+
+ foreach (PropertyInfo pi in type.GetProperties ())
+ Console.WriteLine (pi.GetCustomAttributes (typeof (MyAttribute),
+false).Length);
+ }
+}
+
+public class MyAttribute : Attribute {}
+--------
+
+Actual Results:
+It prints 0.
+
+Expected Results:
+It should print 1.
+
+How often does this happen?
+consistently.
More information about the mono-bugs
mailing list