C#或.Net - 如何获取程序集中所有类型的结构(“.dll”)? [英] C# or .Net - How to get all Types that are structs in an Assembly (".dll")?

查看:802
本文介绍了C#或.Net - 如何获取程序集中所有类型的结构(“.dll”)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在网上看到了关于如何从程序集中获取结构类型(。dll或.exe)但却找不到任何内容的答案。

我知道它需要System.Reflection命名空间,但不知道如何构造和函数来返回结构列表。

I've looked all over the web for answers on how to get struct types from an assembly (".dll" or ".exe") but can't find anything.
I know that it requires the System.Reflection namespace but don't know how to construct and function to return a list of structs.

推荐答案

使用反射循环通过类详细信息和使用以下条件 -

type.IsValueType&& !type.IsPrimitive&& !type.Namespace.StartsWith(System)&& !type.IsEnum



它应该可以帮助你获得课堂上使用的结构列表。



。如果你想在反思为例,尝试使用反射 [ ^ ]。读取其他类型也需要类似的方法。
Using reflection loop through the class details and use the following condition -
type.IsValueType && !type.IsPrimitive && !type.Namespace.StartsWith("System") && !type.IsEnum.

It should help you get a list of structs used in the class.

If you want an example on reflection, try Accessing Attributes by Using Reflection[^]. A similar approach is needed for reading other types as well.


这是如何: http://msdn.microsoft.com/en-us/library/system.reflection.assembly.gettype.aspx [ ^ ]。



如果你想朝这个方向前进,你需要学习反思。并学习如何在文档中找到所需内容。我想接下来你的问题是当你找到一些类型时如何处理类型。 :-)



-SA


这篇关于C#或.Net - 如何获取程序集中所有类型的结构(“.dll”)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆