Humam Helfawi
Humam Helfawi

Reputation: 20324

Getting a list of attributes and its type of class

I pretty sure that this problem has been solved previously here but I do not know even the suitable keyword to search for.

Is it possible in C# to get list of a class or struct attributes and their types in run-time?

P.S. the struct is defined with [StructLayout(LayoutKind.Sequential)] if this makes difference.

Edit

I found this How to get the list of properties of a class?

now the question is : does [StructLayout(LayoutKind.Sequential)] makes any difference ?

Upvotes: 1

Views: 121

Answers (1)

Richard Schneider
Richard Schneider

Reputation: 35464

You can get all the attributes by using Type.GetCustomAttributes.

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

Upvotes: 1

Related Questions