Свойство IsGenericType
List<int> и открытый
List<> -
обобщения,
int -
нет. Аргументы -
GetGenericArguments,
закрытие -
MakeGenericType.
Синтаксис
bool isGeneric = type.IsGenericType;
Пример
Давайте проверить
List<int>:
using System;
using System.Collections.Generic;
class Program
{
static void Main()
{
bool res = typeof(List<int>).IsGenericType;
Console.WriteLine(res);
}
}
Результат выполнения кода:
True
Пример
Давайте проверить
int:
using System;
using System.Collections.Generic;
class Program
{
static void Main()
{
bool res = typeof(int).IsGenericType;
Console.WriteLine(res);
}
}
Результат выполнения кода:
False
Пример
Давайте проверить открытое
List<>:
using System;
using System.Collections.Generic;
class Program
{
static void Main()
{
bool res = typeof(List<>).IsGenericType;
Console.WriteLine(res);
}
}
Результат выполнения кода:
True
Смотрите также
-
метод
GetGenericArguments,
аргументы типа -
метод
MakeGenericType,
закрыть обобщение -
свойство
FullName,
имя с пространством -
Type,
описание типа