1
다음 방법을 사용하고 있지만 Dictionary
에서 TKey
을 반환합니다. Dictionary
은 어떻게 구현합니까 ICollection<KeyValuePair<TKey,TValue>>
어떻게 얻을 수 있습니까 KeyValuePair<TKey,TValue>
?ICollection에서 일반 형식 가져 오기
public static Type GetCollectionGenericType(this Type type)
{
foreach(Type interfaceType in type.GetInterfaces())
{
if(interfaceType.IsGenericType &&
interfaceType.GetGenericTypeDefinition() == typeof(ICollection<>))
{
return type.GetGenericArguments()[ 0 ];
}
}
return null;
}