コード例 #1
0
            /// <summary>
            /// Resolve the value by traversing the property path
            /// </summary>
            /// <param name="root"></param>
            /// <param name="index"></param>
            /// <returns></returns>
            public object GetValue(object root, object[] index)
            {
                if (!IsValid)
                {
                    return(null);
                }

                if (root == null)
                {
                    if (WarnOnGetValue)
                    {
                        Debug.LogWarningFormat("Cannot get value to {0} on a null object", Path);
                    }
                    return(null);
                }

                if (PropertyPathAccessors.ValidateGetter(_pPath, ref _getter))
                {
                    return(_getter(root));
                }

// ReSharper disable once ForCanBeConvertedToForeach - unity has bad foreach handling
                for (int i = 0; i < _pPath.Length; i++)
                {
                    if (root == null)
                    {
                        if (WarnOnGetValue)
                        {
                            Debug.LogWarningFormat("value of {0} was null when getting {1}", Parts[i - 1], Path);
                        }
                        return(null);
                    }

                    var part = GetIdxProperty(i, root);

                    if (part == null)
                    {
                        return(null);
                    }

                    root = part.GetValue(root, null);
                }

                return(root);
            }
コード例 #2
0
            public void SetValue(object root, object value, object[] index)
            {
                if (!IsValid)
                {
                    return;
                }

                if (PropertyPathAccessors.ValidateSetter(_pPath, ref _setter))
                {
                    _setter(root, value);
                    return;
                }

                var i = 0;

                for (; i < _pPath.Length - 1; i++)
                {
                    var part = GetIdxProperty(i, root);

                    if (part == null)
                    {
                        return;
                    }

                    root = part.GetValue(root, null);
                    if (root == null)
                    {
                        if (WarnOnSetValue)
                        {
                            Debug.LogWarningFormat("value of {0} was null when attempting to set {1}", part.Name, Path);
                        }
                        return;
                    }
                }

                _pPath[i].SetValue(root, value, index);
            }