如何在c ++ / cli类中使用c#custom属性 [英] How to use c# custom attribute for c++/cli class

查看:63
本文介绍了如何在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属性。请建议如何纠正这些问题。 


解决方案

您好Chandrakant2411,


感谢您发布此处。


对于您的问题,您在下面使用的库是什么。根据我的搜索,我找不到它。难道 你提供了更多的信息吗?

使用名称空间Sample :: Generic :: TestAutomation :: TestSystem; 
使用名称空间Sample :: CheckIt :: GeneralIO;
使用名称空间Sample :: CheckIt :: Foundation :: GenericLogger;

最好的问候,


Wendy


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. 

解决方案

Hi Chandrakant2411,

Thank you for posting here.

For your question, what is the library you used below. Based on my search, I do not find it. Could  you provide more information of it?

using namespace Sample::Generic::TestAutomation::TestSystem;
using namespace Sample::CheckIt::GeneralIO;
using namespace Sample::CheckIt::Foundation::GenericLogger;

Best Regards,

Wendy


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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆