C#C
C#2y ago
Tinister

Reflection with InlineArrayAttribute?

If I have an object o that I know is a struct with InlineArrayAttribute, how would I go about getting/setting each of the items?

I can get the length with o.GetType().GetCustomAttribute<InlineArrayAttribute>()?.Length

And I can get its field with o.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).Single()

But using fieldInfo.GetValue/fieldInfo.SetValue seems to only get/set the item at index 0 in the array.
Was this page helpful?