获取属性列表及其 class 的类型

Getting a list of attributes and its type of class

我很确定这个问题以前在这里已经解决了,但我什至不知道要搜索合适的关键字。

在 C# 中是否可以在 运行 时间内获取 class 或结构属性及其类型的列表?

P.S。如果这有所不同,则结构用 [StructLayout(LayoutKind.Sequential)] 定义。

编辑

我找到了这个How to get the list of properties of a class?

现在 问题 是:[StructLayout(LayoutKind.Sequential)] 有什么不同吗?

您可以使用Type.GetCustomAttributes获取所有属性。

var attributes = typeof(MyType).GetCustomAttributes(true);