Sdílet prostřednictvím


Compilerfehler CS0616

Aktualisiert: November 2007

Fehlermeldung

"Klasse": ist keine Attributklasse
'class' is not an attribute class

Es wurde versucht, eine Klasse, die keine Attributklasse darstellt, in einem Attributblock zu verwenden. Sämtliche Attributtypen müssen von System.Attribute geerbt werden.

Beispiel

Im folgenden Beispiel wird CS0616 generiert.

// CS0616.cs
// compile with: /target:library
[CMyClass(i = 5)]   // CS0616
public class CMyClass {}

Im folgenden Beispiel wird demonstriert, wie ein Attribut definiert werden kann:

// CreateAttrib.cs
// compile with: /target:library
using System;

[AttributeUsage(AttributeTargets.Class|AttributeTargets.Interface)]
public class MyAttr : Attribute
{
   public int Name = 0;
   public int Count = 0;

   public MyAttr (int iCount, int sName)
   {
      Count = iCount;
      Name = sName;
   }
}

[MyAttr(5, 50)]
class Class1 {}

[MyAttr(6, 60)]
interface Interface1 {}