Is it possible to Define multiple assembly attributes of the sametype in one assembly?

  • Thread starter Thread starter Andreas Mueller
  • Start date Start date
A

Andreas Mueller

Hi all,

I have an attribute class:

[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
class MyAttribute : Attribute
{
public MyAttribute(){ }
}

In one assembly I define the attribute multiple times:

[assembly: MyAttribute()]
[assembly: MyAttribute()]
[assembly: MyAttribute()]

Then I try to access the attributes:

Assembly assembly = this.GetType().Assembly;
object[] att = assembly.GetCustomAttributes(typeof(MyAttribute), true);

Assert.AreEqual(att.Length, 3);//Fails

It only returns the attribute one time. Am I doing something wrong, or
is this simply not possible?

Thanks in advance,
Andy
 
It only returns the attribute one time. Am I doing something wrong, or
is this simply not possible?

It appears that you are correct. I could not apply multiple instances of
an attribute at the assembly level either. I can't seem to find anything
in the ECMA standard that doesn't permit this. Perhaps it's a compiler bug?

Best Regards,
Dustin Campbell
Developer Express Inc
 
Back
Top