https://bugzilla.novell.com/show_bug.cgi?id=377596
Summary: Cannot retrieve Generic Type Parameter Custom Attributes via Reflection Product: Mono: Runtime Version: SVN Platform: x86-64 OS/Version: openSUSE 10.3 Status: NEW Severity: Normal Priority: P5 - None Component: generics AssignedTo: mono-bugs@lists.ximian.com ReportedBy: [EMAIL PROTECTED] QAContact: mono-bugs@lists.ximian.com Found By: --- System.Type.GetCustomAttributes() should return custom attributes on generic type parameters. Sample program: // generic argument attributes? using System; using System.Reflection; [AttributeUsage (AttributeTargets.All)] public class DocAttribute : Attribute { public DocAttribute (string docs) {} } class Foo<[Doc ("T")] T, [Doc ("B")] B> where T : class, new () where B : Attribute { public T Bar { get{return null;}} public void M<[Doc ("X")] X> (X x) { } } class Test { public static void Main () { Type t = typeof(Foo<,>); Type[] tArgs = t.GetGenericArguments (); PrintGenericAttributes (tArgs); MethodInfo m = t.GetMethod ("M"); PrintGenericAttributes (m.GetGenericArguments ()); } static void PrintGenericAttributes (Type[] tArgs) { foreach (Type ta in tArgs) { Console.WriteLine ("Generic Parameter: {0}", ta.Name); Console.WriteLine ("\tGeneric Paramter Attributes: {0}", ta.GenericParameterAttributes); object[] ca = ta.GetCustomAttributes (true); Console.WriteLine ("\tGetCustomAttributes={0}; count={1}", ca, ca.Length); foreach (object o in ca) Console.WriteLine ("\tCustom Attribute: {0}", o.GetType().FullName); Type[] constraints = ta.GetGenericParameterConstraints (); foreach (Type tc in constraints) Console.WriteLine ("\tconstraint: {0}", tc); } } } Expected output: Generic Parameter: T Generic Paramter Attributes: ReferenceTypeConstraint, DefaultConstructorConstraint GetCustomAttributes=System.Object[]; count=1 Custom Attribute: DocAttribute Generic Parameter: B Generic Paramter Attributes: None GetCustomAttributes=System.Object[]; count=2 Custom Attribute: DocAttribute Custom Attribute: System.AttributeUsageAttribute constraint: System.Attribute Generic Parameter: X Generic Paramter Attributes: None GetCustomAttributes=System.Object[]; count=1 Custom Attribute: DocAttribute Notice in the output that GetCustomAttributes() returns a count >= 1 in all cases. Actual output under mono r98602: Generic Parameter: T Generic Paramter Attributes: ReferenceTypeConstraint, DefaultConstructorConstraint GetCustomAttributes=System.Attribute[]; count=0 Generic Parameter: B Generic Paramter Attributes: None GetCustomAttributes=System.Attribute[]; count=1 Custom Attribute: System.AttributeUsageAttribute constraint: System.Attribute Generic Parameter: X Generic Paramter Attributes: None GetCustomAttributes=System.Attribute[]; count=0 Notice that the only parameter with count >= 1 is B, and that's for an AttributeUsageAttribute. -- Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- You are the QA contact for the bug. You are the assignee for the bug. _______________________________________________ mono-bugs maillist - mono-bugs@lists.ximian.com http://lists.ximian.com/mailman/listinfo/mono-bugs