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

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
 
D

Dustin Campbell

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top