Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/274.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
实现一个通用的C++/C#通用接口中的CLI接口_C#_Interface_C++ Cli - Fatal编程技术网

实现一个通用的C++/C#通用接口中的CLI接口

实现一个通用的C++/C#通用接口中的CLI接口,c#,interface,c++-cli,C#,Interface,C++ Cli,我有一个C++/CLI通用接口,如下所示: using namespace System::Collections::Generic; namespace Test { generic <class T> public interface class IElementList { property List<T>^ Elements; }; } using Test; namespace U { public i

我有一个C++/CLI通用接口,如下所示:

using namespace System::Collections::Generic;
namespace Test
{
    generic <class T>
    public interface class IElementList
    {
         property List<T>^ Elements;
    };
}
using Test;
namespace U
{
    public interface IElementLightList<T> : IElementList<T>
        where T : IElementLight
    {
        bool isFrozen();
        bool isPastable();
    }
}
使用命名空间System::Collections::Generic;
名称空间测试
{
通用的
公共接口类IElementList
{
属性列表^元素;
};
}
我想在C#通用接口中实现它,如下所示:

using namespace System::Collections::Generic;
namespace Test
{
    generic <class T>
    public interface class IElementList
    {
         property List<T>^ Elements;
    };
}
using Test;
namespace U
{
    public interface IElementLightList<T> : IElementList<T>
        where T : IElementLight
    {
        bool isFrozen();
        bool isPastable();
    }
}
使用测试;
名称空间U
{
公共接口IElementLightList:IElementList
T:IElementLight在哪里
{
bool是冻结的();
bool isstatable();
}
}
这不起作用,Visual Studio无法看到C++/CLI IElementList界面! 我使用非通用的C++/CLI接口进行了测试,这项工作非常成功


我遗漏了什么?

您声明了一个没有任何访问器方法的属性。您至少需要一个getter:

generic <class T>
    public interface class IElementList {
        property List<T>^ Elements {
            List<T>^ get();
        }
    };
通用
公共接口类IElementList{
属性列表^Elements{
列表^get();
}
};

谢谢,你说得对,但这并不能解决我的问题。在C#中,如果我尝试从非泛型接口继承,这是可行的,但如果我将其设置为泛型接口,则会失败,在这种情况下,C#是盲目的。我在发布之前使用您发布的C#代码对此进行了测试。很好。不知道“失败”或“盲目”可能意味着什么。不过,这个答案肯定会消除你的基本障碍。问另一个问题以正确记录您的新问题。我发现了问题,此代码没有任何错误。非常感谢,你的回答让我找到了真正的问题:它只是一个丢失的#include,ILSpy帮我找到了它!