我有一个 C# 中的抽象泛型类
public abstract class PaymentSystemBase<
TPayInSettings,
TPayOutSettings,
TRefundSettings,
TCashierContract,
TPayoutContract
> : IPaymentSystemInitializable, IPaymentSystem
where TPayInSettings : BasePayInPaymentSystemSettings, new()
where TPayOutSettings : BasePayOutPaymentSystemSettings, new()
where TRefundSettings : BaseRefundPaymentSystemSettings, new()
where TCashierContract : PaymentSystemBaseCashierContract, new()
where TPayoutContract : PaymentSystemBasePayOutContract, new()
{
..
}
这是我的 F# 代码:
module Main =
type CheckoutPaymentIdealUnitTest =
inherit PaymentSystemBase<
BasePayInPaymentSystemSettings,
BasePayOutPaymentSystemSettings,
BaseRefundPaymentSystemSettings,
PaymentSystemBaseCashierContract,
PaymentSystemBasePayOutContract
> with
member x = 1
IDE 抛出错误
The type 'PaymentSystemBase<....>' is not an interface type
是否可以在 F# 中继承 C# 泛型抽象类以及如何正确执行?
我希望收到类似的课程,但在 F# 中:
public class PaymentSystem : PaymentSystemBase<
..,
...,
...,
...,
...
>
{
...
}
需要指定主构造函数来定义只有一个默认构造函数。请参阅 docs(请参阅上面显示默认构造函数的示例)。
所以类似:
module Main =
type CheckoutPaymentIdealUnitTest() =
inherit PaymentSystemBase<
BasePayInPaymentSystemSettings,
BasePayOutPaymentSystemSettings,
BaseRefundPaymentSystemSettings,
PaymentSystemBaseCashierContract,
PaymentSystemBasePayOutContract
>() with
member x = 1