gpt4 book ai didi

c# - F# 接口(interface)实现错误

转载 作者:行者123 更新时间:2023-11-30 21:35:44 25 4
gpt4 key购买 nike

我正在尝试在 F# 中实现以下接口(interface):

using Foundation;
using ObjCRuntime;
using System;
using System.Runtime.CompilerServices;
using UIKit;

namespace Softweb.Xamarin.Controls.iOS
{
[Protocol (Name = "ZLSwipeableViewDataSource", WrapperType = typeof(CardViewDataSourceWrapper))]
public interface ICardViewDataSource : INativeObject, IDisposable
{
//
// Methods
//
[Export ("nextViewForSwipeableView:"), Preserve (Conditional = true), CompilerGenerated]
UIView NextCardForCardView (CardView cardView);
}
}

为此,我有以下代码:

[<Register ("BackgroundAnimationViewControllerDataSource")>]
type BackgroundAnimationViewControllerDataSource () =
interface ICardViewDataSource with
member this.NextCardForCardView(cardView : CardView) =
let card = new UIView()
card.Frame <- CGRect()
card.BackgroundColor <- UIColor.Blue
card.Layer.ShouldRasterize <- true
card

但是这给了我错误:

没有为“ObjCRuntime.INativeObject.get_Handle() : nativeint”提供实现。请注意,所有接口(interface)成员都必须在适当的“接口(interface)”声明下实现和列出,例如'接口(interface) ... 与成员 ...'。

我不明白这一点,因为界面中没有其他方法。

最佳答案

请注意,您的ICardViewDataSource 接口(interface)还实现了INativeObject。 .这意味着您也需要实现该接口(interface)的所有成员。在这种情况下,有一个名为 Handle 的属性那是失踪的。

还值得注意的是它实现了 IDisposable这意味着您可能还需要一个 Dispose 方法。

关于c# - F# 接口(interface)实现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48952342/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com