本文介绍了如何在c ++ / cli类中使用c#custom属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在C ++ / CLI类或方法中使用C#自定义属性。 


请查找下面用c ++ / cli编写的代码和继承的类来自c#class。 


使用命名空间std;
$
使用命名空间系统;

使用命名空间System :: Collections :: Generic ; $
使用命名空间System :: Reflection;

使用命名空间System :: Text;

使用命名空间System :: Runtime :: InteropServices;

使用名称空间Sample :: Generic :: TestAutomation :: TestSystem;

使用名称空间Sample :: CheckIt :: GeneralIO;

using namespace Sample: :CheckIt :: Foundation :: GenericLogger;
$


命名空间ClassLibrary1 {

[TestCase]

公共引用类Class1
:public Sample :: CheckIt :: TestPool :: TestCase

{

private:

static Class1 ^ Instance = nullptr;

GenericLogger ^ Switchmodule_log;

TAIoPortClient ^ _generalio;

bool _testCaseInit = false;


};


[TestCase]属性来自&sample:Generic :: TestAutomation :: TestSystem命名空间。当我将创建的dll加载到我的testapp应用程序中时,我的代码构建正常,我得到了这个  "
可能无法从ClassLibrary1加载TestCases!程序集没有定义TestCases"
 。根据我的理解,应用程序无法读取TestCase属性。请建议如何纠正这些问题。 


解决方案

I want to use C# custom attribute for C++/CLI class or method. 

Please find the below code which i have written in c++/cli and class inherited from c# class. 

using namespace std;
using namespace System;
using namespace System::Collections::Generic;
using namespace System::Reflection;
using namespace System::Text;
using namespace System::Runtime::InteropServices;
using namespace Sample::Generic::TestAutomation::TestSystem;
using namespace Sample::CheckIt::GeneralIO;
using namespace Sample::CheckIt::Foundation::GenericLogger;

namespace ClassLibrary1 {
[TestCase]
public ref class Class1: public Sample::CheckIt::TestPool::TestCase
{
private:
static Class1^ Instance = nullptr;
GenericLogger^ Switchmodule_log;
TAIoPortClient^ _generalio;
bool _testCaseInit = false;

};

[TestCase] attribute coming from Sample::Generic::TestAutomation::TestSystem namespace. my code is building properly when i loaded my created dll into my testapp application, i am this getting "Could not load TestCases from the ClassLibrary1!Assembly has no TestCases defined" . as per my understanding the application is not able to read the TestCase attribute. Please suggest how to rectify these issue. 

解决方案


这篇关于如何在c ++ / cli类中使用c#custom属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 07:26