Skip to content

Commit a49696b

Browse files
authored
Skip null items when converting collections to dtos (#134)
1 parent 79aff47 commit a49696b

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

Assets/Plugins/StreamChat/Core/Helpers/ICollectionExt.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ public static List<TDto> TrySaveToDtoCollection<TSource, TDto>(this List<TSource
2323

2424
foreach (var item in source)
2525
{
26+
if (item == null)
27+
{
28+
continue;
29+
}
2630
dtos.Add(item.SaveToDto());
2731
}
2832

Assets/Plugins/StreamChat/Core/Helpers/IDictionaryExt.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ public static Dictionary<TKey, TDto> TrySaveToDtoDictionary<TDto, TSource, TKey>
2020

2121
foreach (var sourceKeyValue in source)
2222
{
23+
if (sourceKeyValue.Value == null)
24+
{
25+
continue;
26+
}
27+
2328
dict.Add(sourceKeyValue.Key, sourceKeyValue.Value.SaveToDto());
2429
}
2530

@@ -39,6 +44,11 @@ public static Dictionary<TKey, TSource> TryLoadFromDtoDictionary<TDto, TSource,
3944

4045
foreach (var sourceKeyValue in dtos)
4146
{
47+
if (sourceKeyValue.Value == null)
48+
{
49+
continue;
50+
}
51+
4252
dict.Add(sourceKeyValue.Key, new TSource().LoadFromDto(sourceKeyValue.Value));
4353
}
4454

0 commit comments

Comments
 (0)