[Mono-dev] [PATCH] BUG in TypeDescriptor.GetAttributes : Ignores overriden attributes
Ivan N. Zlatev
contact at i-nz.net
Fri Sep 1 17:09:43 EDT 2006
The current implementation of TypeDescriptor.GetAttributes ignores
overriden attributes and returns the bottom most in the inheritance
tree. The attached patch fixes that. I have also attached a test case
so you can observe the wrong behaviour. The patch also does whitespace
cleanup.
Please review and commit.
P.S: The fix is this and everything else is just the whitespace cleanup:
=== START ===
protected AttributeCollection GetAttributes (IComponent comp)
{
if (_attributes != null)
return _attributes;
-
+
bool cache = true;
object[] ats = _infoType.GetCustomAttributes (true);
Hashtable t = new Hashtable ();
- foreach (Attribute at in ats)
- t [at.TypeId] = at;
-
- if (comp != null && comp.Site != null)
+
+ // Filter the custom attributes, so that only the top
+ // level of the same type are left.
+ //
+ for (int i = ats.Length -1; i > 0; i--) {
+ t [((Attribute) ats[i]).TypeId] = ats[i];
+ }
+
+ if (comp != null && comp.Site != null)
{
ITypeDescriptorFilterService filter =
(ITypeDescriptorFilterService) comp.Site.GetService
(typeof(ITypeDescriptorFilterService));
cache = filter.FilterAttributes (comp, t);
}
=== END ===
--
Ivan N. Zlatev
Web: http://www.i-nZ.net
GPG Key: http://files.i-nZ.net/i-nZ.asc
"It's all some kind of whacked out conspiracy."
-------------- next part --------------
A non-text attachment was scrubbed...
Name: TypeDescriptor.GetAttributes_Ignores_overriden_attributes_fix.patch
Type: text/x-patch
Size: 10103 bytes
Desc: not available
Url : http://lists.ximian.com/pipermail/mono-devel-list/attachments/20060902/00405ca7/attachment.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.cs
Type: application/octet-stream
Size: 937 bytes
Desc: not available
Url : http://lists.ximian.com/pipermail/mono-devel-list/attachments/20060902/00405ca7/attachment.obj
More information about the Mono-devel-list
mailing list