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

时间:2011-12-28 21:44:51

标签: .net c#-4.0 interop c++-cli

我一直在尝试开发用于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;
    }
};
}

我的C#实现如下:

使用System;

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

我收到以下错误:

错误CS0570:语言

不支持“TestMessage”

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

任何帮助将不胜感激

1 个答案:

答案 0 :(得分:13)

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