我有 1. CLI 库,具有声明的接口(InterfaceCLI)和实现的值类型(PointD ) 2. 具有类( PointD )的C# 库,从 1 实现接口
问题是 C# 上的奇怪接口实现。它需要这样的代码 public ValueType GetPoint() 而不是 public PointD GetPoint()
示例代码 CLI:
public value struct PointD
//public ref class PointD
{
public:
PointD(double x, double y);
// Some stuff
};
public interface class InterfaceCLI
{
public:
double Foo();
PointD^ GetPoint();
};
示例代码 C#:
public class Class1 : InterfaceCLI
{
public double Foo()
{
PointD x=new PointD( 1.0 , 2.7 );
return x.Y;
}
public ValueType GetPoint()
{
throw new NotImplementedException();
}
/*
public PointD GetPoint()
{
throw new NotImplementedException();
}
*/
}
为什么它在 Class1 类中需要 ValueType 而不是 PointD?!