如何使用 Xamarin.iOS 将某些内容分配给 nil [英] How to assign something to nil using Xamarin.iOS

查看:16
本文介绍了如何使用 Xamarin.iOS 将某些内容分配给 nil的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Xamarin.iOS 项目中使用 Nuget 绑定包,但在尝试将对象分配给 null 时遇到了问题.根据我找到的指向库的 Objective-C 版本的链接,您可以将要禁用的对象分配为 nil.不幸的是,C# 没有 nil 关键字,只有 null,并且每当我将其属性之一分配给 null 时,库都会抛出 ArgumentNullException.有谁知道如何将 Xamarin.iOS 中的某些内容专门分配给 nil 而不是 null?

I am using a Nuget bindings package in a Xamarin.iOS project, and I am running into trouble when attempting to assign an object to null. According to a link I found to the Objective-C version of the library, you can just assign the objects you want to disable to nil. Unfortunately, C# doesn't have a nil keyword, only null, and the library throws an ArgumentNullException whenever I assign one of its Properties to null. Does anyone know how to specifically assign something in Xamarin.iOS to nil instead of null?

推荐答案

这是绑定库的问题.

在绑定库时,作者必须选择允许用户将 null 传递给参数,而且他们似乎忘记这样做了(如果他们不允许这样做,则会得到 ArgumentNullException你提到了).

When binding a library, the authors have to opt in to allow users to pass null to parameters, and it seems they forgot to do this (if they don't allow it, you get the ArgumentNullExceptionyou mention).

联系作者,告诉他们需要添加 [NullAllowed] 相关属性的属性.

Contact the authors, and tell them they need to add the [NullAllowed] attribute on the property in question.

这篇关于如何使用 Xamarin.iOS 将某些内容分配给 nil的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆