Таки
снова даАвтор: Sinix
Дата: 07.12.16
.
using System;
using ConsoleApp;
[assembly: My("A"), My("A"), My("B")]
namespace ConsoleApp
{
[AttributeUsage(AttributeTargets.All, AllowMultiple = true)]
public class MyAttribute : Attribute
{
public MyAttribute(string origin)
{
Origin = origin;
}
public string Origin { get; }
}
[My("A"), My("A"), My("B")]
class Program
{
static void Main(string[] args)
{
var t = typeof(Program);
Console.WriteLine(
"Type-level: {0} attributes",
Attribute.GetCustomAttributes(t, typeof(MyAttribute)).Length);
Console.WriteLine(
"Assembly-level: {0} attributes",
Attribute.GetCustomAttributes(t.Assembly, typeof(MyAttribute)).Length);
Console.ReadKey();
}
}
}
Кто объяснит вывод — тому медаль. Воспроизводится как минимум на компиляторах c#5 и выше. Вывод отдельным ответом ибо спойлер.