How do I get a list of all the properties of a class?
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Generic Generics in Managed C++
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
Based on @MarcGravell's answer, here's a version that works in Unity C#.
That's my solution
This function is for getting list of Class Properties.
You can use Reflection to do this: (from my library - this gets the names and values)
This thing will not work for properties with an index - for that (it's getting unwieldy):
Also, to get only public properties: (see MSDN on BindingFlags enum)
This works on anonymous types, too!
To just get the names:
And it's just about the same for just the values, or you can use:
But that's a bit slower, I would imagine.
Here is improved @lucasjones answer. I included improvements mentioned in comment section after his answer. I hope someone will find this useful.
You can use reflection.