Reputation: 20324
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.
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
Reputation: 35464
You can get all the attributes by using Type.GetCustomAttributes.
var attributes = typeof(MyType).GetCustomAttributes(true);
Upvotes: 1