Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compare closed type with open type

I'm curious how to check if given type is closed version of open type. For instance

public bool IsGenericList(Type source)
{
    return (source.IsGenericType &&
            /*here goes the manipulation on source type*/ == typeof(List<>));
}
like image 610
jethro Avatar asked Oct 14 '10 10:10

jethro


People also ask

What are the similarities between open and closed circulatory systems?

What are the Similarities Between Open Circulatory System and Closed Circulatory System? Both open circulatory system and closed circulatory system transport oxygen and nutrients to the organs and removes waste products. Also, they both have a heart and vessels.

What is closed type of circulatory system?

In a closed circulatory system, blood is contained inside blood vessels, circulating unidirectionally (in one direction) from the heart around the systemic circulatory route, then returning to the heart again.

What is one advantage of closed circulatory systems as compared to open circulatory systems?

In what way is a closed circulatory system more efficient than an open circulatory system? a. A closed circulatory system is a closed loop and therefore does not require a heart for pumping blood.

Why is a closed circulatory system better?

The closed circulatory system has more advantages over the open circulatory system. 1. The blood transfers faster in the closed system, thus oxygen, nutritients, and wastes transport fast also.


1 Answers

Try Type.GetGenericTypeDefinition:

public bool IsGenericList(Type source)
{
    return source.IsGenericType &&
           source.GetGenericTypeDefinition() == typeof(List<>);
}
like image 124
Jon Skeet Avatar answered Oct 27 '22 02:10

Jon Skeet