[Mono-list] BUG: MonoCustomAttribute (System.Reflection)

Martin Aliger martin_aliger@email.cz
Fri, 27 Sep 2002 14:49:30 +0200 (CEST)


Hi all,

Still trying get NAnt works under mono and found this bug completely breaks NAnt core:

Static method Attribute.GetCustomAttribute(from,type) queries whether something has or not attributte of such type. MS doc says (after very long study) that it returns "attribute which is assignable to this type". That means - not only attributes of this type, but also derived attributes.

There is example (this should be tested on MS .net, but I do not have one available)
------
using System;
using System.Reflection;

class Test
{
	string _test = "ahoj";

	class BaseAttribute : Attribute
	{
	}

	class DerivedAttribute : BaseAttribute
	{
	}

	[DerivedAttribute]
	public string TestProp { get{ return _test;} }

	static public void Main()
	{
		Test t=new Test();
		PropertyInfo p=t.GetType().GetProperty("TestProp",BindingFlags.Public|BindingFlags.Instance);
		Console.WriteLine(p);

		object[] ats;
		object at=Attribute.GetCustomAttribute(p,typeof(BaseAttribute));
		Console.WriteLine(at);

		ats=p.GetCustomAttributes(true);
		foreach(object a in ats) {
			Console.WriteLine(a);
		}
	}

}
------

Martin


______________________________________________________________________________
SB KOMPLET®  Informační ekonomický systém http://www.sb-komplet.cz  
…umíme svoji práci!