给定以下代码:
var type1 = typeof(int[]); // Int32[]
var type2 = Array.CreateInstance(elementType: typeof(int),
lengths: new [] {0},
lowerBounds: new []{1}).GetType(); // Int32[*]
如果给定一个数组类型(一个类型,其中.IsArray返回true),我如何可靠地区分这两种数组类型?
最好不要使用任何hacky解决方案(如实例化类型或在名称中查找“*”)。
背景:我正在构建一个序列化程序,我需要它适用于所有类型,因此常量比较(如== typeof(int []))不起作用。