-
Notifications
You must be signed in to change notification settings - Fork 146
Expand file tree
/
Copy pathEmptyCollectionToObjectConverter.cs
More file actions
32 lines (28 loc) · 1.11 KB
/
EmptyCollectionToObjectConverter.cs
File metadata and controls
32 lines (28 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Collections;
namespace CommunityToolkit.WinUI.Converters;
/// <summary>
/// This class converts a collection size into an other object.
/// Can be used to convert to bind a visibility, a color or an image to the size of the collection.
/// </summary>
public partial class EmptyCollectionToObjectConverter : EmptyObjectToObjectConverter
{
/// <summary>
/// Checks collection for emptiness.
/// </summary>
/// <param name="value">Value to be checked.</param>
/// <returns>True if value is an empty collection or does not implement IEnumerable, false otherwise.</returns>
protected override bool CheckValueIsEmpty(object value)
{
bool isEmpty = true;
var collection = value as IEnumerable;
if (collection != null)
{
var enumerator = collection.GetEnumerator();
isEmpty = !enumerator.MoveNext();
}
return isEmpty;
}
}