C# Reflection – How to Get a Property Value

c++reflection

I have the following code:

FieldInfo[] fieldInfos;
fieldInfos = GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Instance);

What I am trying to do is get the value of one of my properties of the current instantiated instance at runtime using reflection. How can I do this?

Best Answer

Something like this should work:

var value = (string)GetType().GetProperty("SomeProperty").GetValue(this, null);
Related Question