Sunday, March 11, 2012

CLR Supported Custom Attributes

After working with the CLR for more than a decade, once in a while I still run into surprising behavior.

It turns out that the (non pseudo-) custom attributes that CLR recognizes are only matched by name, not assembly.

So you can do this for example:

using System;
using System.Threading;

namespace System {
  class ThreadStaticAttribute : global::System.Attribute { }
}

class Program {
  [System.ThreadStaticAttribute]
  static int foo;

  public static void Main() {
    WriteFoo();
    foo = 42;

Read more: IKVM.NET Weblog
QR: Inline image 1

Posted via email from Jasper-Net