Kompilatorfel C3450

"type": inte ett attribut; kan inte ange [System::AttributeUsageAttribute] eller [Windows::Foundation::Metadata::AttributeUsageAttribute]

Anmärkningar

Ett användardefinierat hanterat attribut måste ärva från AttributeCollection. Ett Windows Runtime-attribut måste definieras i Windows::Foundation::Metadata namnområdet.

Mer information finns iUser-Defined Attribut.

Example

I följande exempel genereras C3450 och hur du åtgärdar det.

// C3450.cpp
// compile with: /clr
// C3450 expected
using namespace System;
using namespace System::Security;
using namespace System::Security::Permissions;

public ref class MyClass {};

class MyClass2 {};

[attribute(AttributeTargets::All)]
ref struct AtClass {
   AtClass(Type ^) {}
};

[attribute(AttributeTargets::All)]
ref struct AtClass2 {
   AtClass2() {}
};

// Apply the AtClass and AtClass2 attributes to class B
[AtClass(MyClass::typeid), AtClass2]
[AttributeUsage(AttributeTargets::All)]
// Delete the following line to resolve.
ref class B {};
// Uncomment the following line to resolve.
// ref class B : Attribute {};