Last active
July 10, 2020 15:16
-
-
Save gsscoder/855f4d4bce0190f9b2f7ed70a4787d67 to your computer and use it in GitHub Desktop.
C# extension method to discover if a property is a collection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections.Generic; | |
using System.Reflection; | |
public static class PropertyInfoExtensions | |
{ | |
public static bool IsEnumerable(this PropertyInfo property) => | |
(property.PropertyType.IsGenericType && | |
property.PropertyType.GetGenericTypeDefinition() == typeof(IEnumerable<>)) || | |
property.PropertyType.GetInterface(typeof(IEnumerable<>).FullName) != null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment