[Foundation] Fix code to not cause a potential null error when compiling using the .NET 5 BCL. (#8978)

Fix code to not cause a potential null reference error from csc when compiling
using the .NET 5 BCL:

> Foundation/DictionaryContainer.cs(330,47): error CS8604: Possible null reference argument for parameter 'source' in 'IEnumerable<NSObject> Enumerable.Select<T, NSObject>(IEnumerable<T> source, Func<T, NSObject> selector)'.

And do so by rewriting Linq code, which also makes the code much less memory
hungry and more performant.
This commit is contained in:
Rolf Bjarne Kvinge 2020-07-01 08:32:42 +02:00 коммит произвёл GitHub
Родитель e4523d8f9d
Коммит 9ace0c6797
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
1 изменённых файлов: 6 добавлений и 3 удалений

Просмотреть файл

@ -27,7 +27,6 @@
//
using System;
using System.Linq;
using System.Runtime.InteropServices;
#if !COREBUILD
@ -326,8 +325,12 @@ namespace Foundation {
protected void SetArrayValue<T> (NSString key, T[]? values)
{
if (NullCheckAndRemoveKey (key, values == null))
Dictionary [key] = NSArray.FromNSObjects (values.Select (x => NSObject.FromObject (x)).ToArray ());
if (NullCheckAndRemoveKey (key, values == null)) {
var nsValues = new NSObject [values!.Length];
for (var i = 0; i < values.Length; i++)
nsValues [i] = NSObject.FromObject (values [i]);
Dictionary [key] = NSArray.FromNSObjects (nsValues);
}
}
protected void SetArrayValue (NSString key, string[]? values)