public static object GetFieldOrPropertyValue()

in SupportingScripts/Editor/Scripts/UnitySerializationPath.cs [72:120]


        public static object GetFieldOrPropertyValue(string fieldName, object obj, bool includeAllBases = false, BindingFlags bindings = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)
        {
            if (fieldName.StartsWith(ArrayPrefix))
            {
                var list = (IList)obj;
                int index = int.Parse(fieldName.Substring(ArrayPrefix.Length, fieldName.Length - ArrayPrefix.Length - ArraySuffix.Length));

                if (index >= list.Count)
                {
                    throw new ArgumentException("List is not long enough to hold property. Was SerializedObject.ApplyModifiedProperties called after the list was expanded?");
                }

                return list[index];
            }
            else
            {
                FieldInfo field = obj.GetType().GetField(fieldName, bindings);
                if (field != null)
                {
                    return field.GetValue(obj);
                }

                PropertyInfo property = obj.GetType().GetProperty(fieldName, bindings);
                if (property != null)
                {
                    return property.GetValue(obj, null);
                }

                if (includeAllBases)
                {
                    foreach (Type type in GetBaseClassesAndInterfaces(obj.GetType()))
                    {
                        field = type.GetField(fieldName, bindings);
                        if (field != null)
                        {
                            return field.GetValue(obj);
                        }

                        property = type.GetProperty(fieldName, bindings);
                        if (property != null)
                        {
                            return property.GetValue(obj, null);
                        }
                    }
                }
            }

            return null;
        }