0

我已经通过目标 C 框架创建了绑定库,有一个类在 Xamarin IOS 中扩展其他接口的 NsObject 类型(KsEvent),在转换过程中出错,无法将 KSMEvent 的类型转换为 KsEvent。

api定义:

// @interface KSMEvent : NSObject <KsEvent> 
    [BaseType(typeof(NSObject))]
    interface KSMEvent : KsEvent
    {
        // @property NSDictionary * _Nullable userInfo;
        [NullAllowed, Export("userInfo", ArgumentSemantic.Assign)]
        NSDictionary UserInfo { get; set; }

        // -(instancetype _Nonnull)initWithName:(NSString * _Nonnull)name object:(id _Nullable)object userInfo:(NSDictionary * _Nullable)userInfo;
        [Export("initWithName:object:userInfo:")]
        IntPtr Constructor(string name, [NullAllowed] NSObject @object, [NullAllowed] NSDictionary userInfo);
    }

[BaseType(typeof(NSObject))]
    [Protocol, Model]
    interface KsEvent
    {
        // @required -(NSString * _Nonnull)getName;
        [Abstract]
        [Export("getName")]     
        string Name { get; }

        // @required -(id _Nullable)getObject;
        [Abstract]
        [NullAllowed, Export("getObject")]      
        NSObject Object { get; }

        // @required -(NSDictionary * _Nullable)getUserInfo;
        [Abstract]
        [NullAllowed, Export("getUserInfo")]        
        NSDictionary UserInfo { get; }
    }

Xamarin IOS:

KSMEvent kSMEvent = new KSMEvent();
KsEvent ksEvent = (KsEvent)kSMEvent;

** 错误:无法将 KSMEvent 类型转换为 KsEvent。**

4

0 回答 0