[Mono-bugs] [Bug 706329] New: System.ComponentModel.TypeDescriptor.GetAttributes() does not respect calls to AddAttributes()

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Sun Jul 17 23:22:59 EDT 2011


https://bugzilla.novell.com/show_bug.cgi?id=706329

https://bugzilla.novell.com/show_bug.cgi?id=706329#c0


           Summary: System.ComponentModel.TypeDescriptor.GetAttributes()
                    does not respect calls to AddAttributes()
    Classification: Mono
           Product: Mono: Class Libraries
           Version: SVN
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: Normal
          Priority: P5 - None
         Component: System
        AssignedTo: mono-bugs at lists.ximian.com
        ReportedBy: nullsquared at gmail.com
         QAContact: mono-bugs at lists.ximian.com
          Found By: ---
           Blocker: ---


Created an attachment (id=440501)
 --> (http://bugzilla.novell.com/attachment.cgi?id=440501)
test class to demonstrate the issue

Description of Problem:
System.ComponentModel.TypeDescriptor.GetAttributes() does not respect calls to
TypeDescriptor.AddAttributes()

Steps to reproduce the problem:
1. Add any attribute to a class type with TypeDescriptor.AddAttributes()
2. Get a list of attributes of a class type with TypeDescriptor.GetAttributes()
- the added attributes won't be there

Actual Results:
Attributes before adding TestAttributeB:
TestTypeConverter.TestAttributeA

Adding TestAttributeB to TestClass

Attributes after adding TestAttributeB:
TestTypeConverter.TestAttributeA

Expected Results:
Attributes before adding TestAttributeB:
TestTypeConverter.TestAttributeA

Adding TestAttributeB to TestClass

Attributes after adding TestAttributeB:
TestTypeConverter.TestAttributeA
TestTypeConverter.TestAttributeB

How often does this happen? 
Every time

Additional Information:
Mono's implementation of TypeDescriptor.GetAttributes() gets the attributes of
a class type by using the Type class itself; the Type class will not contain
attributes registered at run-time via TypeDescriptor.AddAttributes(), so this
is wrong.

Microsoft's implementation of TypeDescriptor.GetAttributes() simply calls
GetDescriptor().GetAttributes(), which not only return's the Type's attributes,
but it also returns any attributes registered with the TypeDescriptor.

As such, a fix in a client's code could look like this:
//attribs = TypeDescriptor.GetAttributes(typeof(TestClass));
attribs =
TypeDescriptor.GetProvider(typeof(TestClass)).GetTypeDescriptor(typeof(TestClass)).GetAttributes();

The issue is not that simple, though. TypeDescriptor uses its own
GetAttributes() internally when, for example, you call GetConverter() - this
means that you cannot use a custom type converter.

-- 
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.


More information about the mono-bugs mailing list