如何将 C# class 属性设置为 C++/CLI class
How to set C# class attribute into C++/CLI class
我想将测试用例属性设置到我的 c++/cli class。我正在为该属性添加 dll 引用。请注意,我在 C# 中用于属性设置的 dll。请找到以下代码:
using namespace Sample::Generic::TestAutomation::TestSystem;
namespace ClassLibrary1 {
[AttributeUsage(Sample::Generic::TestAutomation::TestSystem::TestCase)]
public ref class Class1 : public Sample::CheckIt::TestPool::TestCase
{
private:
static Class1^ Instance = nullptr;
GenericLogger^ Switchmodule_log;
TAIoPortClient^ _generalio;
bool _testCaseInit = false;
};
当我尝试使用此属性时,出现以下错误:
Error C2275 'Sample::Generic::TestAutomation::TestSystem::TestCase':
illegal use of this type as an
expression ClassLibrary1 c:\users\chan\documents\visual studio
2015\projects\classlibrary1\classlibrary1\ClassLibrary1.h 17
AttributeUsage
用于定义新属性。当您定义 MyFancyNewAttribute 时,您使用 AttributeUsage
来声明该属性是否用于 类、方法或其他。
你想多了。要使用属性,它的语法与 C# 中的语法相同。
[TestCase]
public ref class Class1
我想将测试用例属性设置到我的 c++/cli class。我正在为该属性添加 dll 引用。请注意,我在 C# 中用于属性设置的 dll。请找到以下代码:
using namespace Sample::Generic::TestAutomation::TestSystem;
namespace ClassLibrary1 {
[AttributeUsage(Sample::Generic::TestAutomation::TestSystem::TestCase)]
public ref class Class1 : public Sample::CheckIt::TestPool::TestCase
{
private:
static Class1^ Instance = nullptr;
GenericLogger^ Switchmodule_log;
TAIoPortClient^ _generalio;
bool _testCaseInit = false;
};
当我尝试使用此属性时,出现以下错误:
Error C2275 'Sample::Generic::TestAutomation::TestSystem::TestCase': illegal use of this type as an expression ClassLibrary1 c:\users\chan\documents\visual studio 2015\projects\classlibrary1\classlibrary1\ClassLibrary1.h 17
AttributeUsage
用于定义新属性。当您定义 MyFancyNewAttribute 时,您使用 AttributeUsage
来声明该属性是否用于 类、方法或其他。
你想多了。要使用属性,它的语法与 C# 中的语法相同。
[TestCase]
public ref class Class1