1个回答

4

以下是考虑泛型的检查方法。如果x或y为null,它将抛出NRE异常。因此,如果您希望进行更加健壮的检查,请添加null检查。

public bool Equals(Type x, Type y)
{
    var a = x.IsGenericType ? x.GetGenericTypeDefinition() : x;
    var b = y.IsGenericType ? y.GetGenericTypeDefinition() : y;
    return a == b;
}

1
谢谢。这正是我正在寻找的。 - Little Endian

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接