gpt4 book ai didi

c# - 封闭式与开放式比较

转载 作者:太空狗 更新时间:2023-10-29 18:19:20 25 4
gpt4 key购买 nike

我很好奇如何检查给定类型是否是开放类型的封闭版本。例如

public bool IsGenericList(Type source)
{
return (source.IsGenericType &&
/*here goes the manipulation on source type*/ == typeof(List<>));
}

最佳答案

尝试 Type.GetGenericTypeDefinition :

public bool IsGenericList(Type source)
{
return source.IsGenericType &&
source.GetGenericTypeDefinition() == typeof(List<>);
}

关于c# - 封闭式与开放式比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3932193/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com