我自己的托管类型为C++/CLI类库中的arg:CS0570:该语言不支持

xcv*_*cvd 5 .net interop c++-cli c#-4.0

我一直在尝试开发一个用于C#的C++/CLI库,我遇到了以下问题.如果我们将我的托管引用类如下:

namespace Library
{
using namespace System;

public ref class Test
{
internal:
    String^ internalString;
public:
    Test()
    {
        internalString = gcnew String("Hey There");
    }
    ~Test()
    {

    }
};

public ref class TestImplement
{
public:
    static String^ TestMessage(Test test)
    {
        return test.internalString;
    }
};
}
Run Code Online (Sandbox Code Playgroud)

我的C#实现如下:

使用系统;

namespace AddProgram
{
class Program
{
    static void Main(string[] args)
    {
        Library.Test test = new Library.Test();
        Console.WriteLine(Library.TestImplement.TestMessage(test));
        Console.Read();
    }
}
}
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

错误CS0570:该语言不支持"TestMessage"

据我所知,这是由于将类型Library.Test作为参数传递.我不明白为什么我收到此消息,我希望可以从我的参考库传递类型.

任何帮助,将不胜感激

Mik*_*keP 13

您需要将TestMessage声明为引用 Library.Test,这意味着像对String ^一样使用插入符号(^).C++/CLI允许您通过不使用插入符来使用值类型语义(排序)来处理引用类型,但C#没有等效的功能,这就是您收到该错误的原因.