Here's how:
C#
protected void CheckInterfaceImpl(Type someType)
{
Type[] listInterfaces = someType.GetType().GetInterfaces();
foreach (Type t in listInterfaces)
{
if (t.GetGenericTypeDefinition() == typeof(IEnumerable<>))
{
// Implements IEnumerable<T>
}
else
{
// Does not Implement IEnumerable<T>
}
}
}
VB.NET
Protected Sub CheckInterfaceImpl(ByVal someType As Type)
Dim listInterfaces() As Type = someType.GetType.GetInterfaces()
For Each t As Type In listInterfaces
If t.GetGenericTypeDefinition() Is GetType(IEnumerable(Of )) Then
' Implements IEnumerable<T>
Else
' Does not Implement IEnumerable<T>
End If
Next t
End Sub
Know a better way? Share it here. I am all ears!
Bookmark this link on del.icio.us (saved by 0 users)
Did you like this post?
|
|
|
||
|
|
|
|
|
|
|
subscribe via rss |
|
subscribe via e-mail |
|
|
print this post |
|
follow me on twitter |





comments
0 Responses to "Determine if an object implements IEnumerable of (T)"Post a Comment