共用方式為


編譯器錯誤 C3450

'type':不是屬性,無法指定 [System::AttributeUsageAttribute] 或 [Windows::Foundation::Metadata::AttributeUsageAttribute]

使用者定義的 Managed 屬性必須繼承自 AttributeCollection。 Windows 執行階段屬性必須定義於 Windows::Foundation::Metadata 命名空間。

如需詳細資訊,請參閱 User-Defined Attributes

範例

下列範例會產生 C3450,並示範如何修正此問題:

// 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 {};