在运行时获取“类型”类型
我有一个变量prop
type propertyinfo
。
我想创建一个类型
变量,该变量是prop.propertytype
的数组。
对于普通类型,我可以做typeof(myType<>)。makeGenerictype(prop.propertytype)
,但数组不是通用的。
到目前为止,我能想到的最好的事情是:
Array.CreateInstance(prop.PropertyType, 0).GetType()
但这确实是不可能的,我错过了什么吗?
I have a variable prop
of type PropertyInfo
.
I want to create a Type
variable which is an array of the prop.PropertyType
.
For normal generic types I can do typeof(myType<>).MakeGenericType(prop.PropertyType)
but arrays aren't generics.
The best I've been able to come up with so far is:
Array.CreateInstance(prop.PropertyType, 0).GetType()
But this is really inelligant, am I missing something?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
type.makearraytype()
来执行此操作:You can use
Type.MakeArrayType()
to do this: