有没有办法检查一个类型是一个记录?
class Program
{
static void Main(string[] args)
{
IsRecord(typeof(Person)); // true
}
static bool IsRecord(Type type)
{
// ...
}
}
public record Person
{
public string LastName { get; }
public string FirstName { get; }
public Person(string first, string last) => (FirstName, LastName) = (first, last);
}
Type.IsValueType
吗? - JoelFan